',
scope: {
ngReadonly: "=ngReadonly",
},
link: function(scope, element, attrs, ngModel, $parse) {
if (!ngModel) return;
scope.model = ngModel;
scope.value = ngModel.$modelValue;
scope.oldValue = undefined;
if (attrs.name)
scope.name = attrs.name;
if (attrs.class)
scope.class = attrs.class;
ngModel.$formatters.push(function(modelValue) {
// First time only
if (scope.oldValue === undefined)
scope.oldValue = modelValue;
if (modelValue === undefined || modelValue == '')
return null;
scope.value = modelValue;
return modelValue;
});
ngModel.$parsers.push(function(modelValue) {
if (modelValue === undefined || modelValue == '')
return null;
scope.value = modelValue;
return modelValue;
});
ngModel.$render = function(){
if (!ngModel.$modelValue || ngModel.$modelValue == '')
{
scope.value = null;
ngModel.$setViewValue(null);
return;
}
};
},
controller: function($scope) {
$scope.resizeCanvas = function() {
var ratio = Math.max(window.devicePixelRatio || 1, 1);
var canvas = $scope.canvas;
if (!canvas)
return;
canvas.width = canvas.offsetWidth * ratio;
canvas.height = canvas.offsetHeight * ratio;
canvas.getContext("2d").scale(ratio, ratio);
$scope.signaturePad.clear();
}
$scope.show = function() {
if (!$scope.overlayElement)
$scope.overlayElement = document.getElementById("signature-pad-overlay");
if ($scope.overlayElement)
$scope.overlayElement.style.display = "block";
if (!$scope.canvas)
{
var wrapperElement = document.getElementById("signature-pad");
if (wrapperElement)
$scope.canvas = wrapperElement.querySelector("canvas");
}
if ($scope.wrapperElement)
$scope.canvas = $scope.wrapperElement.querySelector("canvas");
if ($scope.canvas)
{
$scope.signaturePad = new SignaturePad($scope.canvas, {
backgroundColor: 'rgba(255, 255, 255, 0)',
penColor: 'rgb(0, 0, 0)'
});
$scope.resizeCanvas();
}
}
$scope.hide = function() {
if (!$scope.overlayElement)
$scope.overlayElement = document.getElementById("signature-pad-overlay");
if ($scope.overlayElement)
$scope.overlayElement.style.display = "none";
}
$scope.onFocus = function(){
$scope.show();
};
$scope.clear = function() {
if ($scope.signaturePad)
$scope.signaturePad.clear();
}
$scope.ok = function() {
if ($scope.signaturePad && !$scope.signaturePad.isEmpty()) {
$scope.value = $scope.signaturePad.toSVG();
$scope.model.$setViewValue($scope.value);
}
$scope.hide();
}
$scope.cancel = function() {
if ($scope.signaturePad)
$scope.signaturePad.clear();
$scope.model.$setViewValue($scope.oldValue);
$scope.hide();
}
}
};
}]);
t3_ng_app_index.directive('t3Field', ['$mdMedia', '$compile', '$http',
function ($mdMedia, $compile) {
return {
require: '?ngModel',
replace: true,
template: '
',
scope: {
ngReadonly: "=ngReadonly",
showLabels: "=t3ShowLabels",
loginData: "=t3LoginData",
editboxForm: "=t3EditboxForm",
fieldLayoutData: "=t3FieldLayoutData",
entityLayoutData: "=t3EntityLayoutData",
entityData: "=t3EntityData"
},
controller: function($scope, $http) {
var checkValues = [false, true, null];
var len = checkValues.length;
var index = 0;
$scope.checkBoxIsChecked = function(entity, fieldName) {
if (!entity || !fieldName)
return false;
return (entity[fieldName] == true);
}
$scope.checkBoxIsIndeterminated = function(entity, fieldName) {
if (!entity || !fieldName)
return true;
return (entity[fieldName] == null);
}
$scope.checkBoxModelChange = function(entity, fieldName) {
}
$scope.transformChip = function(chip) {
// If it is an object, it's already a known chip
if (angular.isObject(chip)) {
return chip;
}
}
$scope.buildLinkToOtherEntityId = function(otherEntity, id) {
//var url = T3_APP_base_url + '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D';
var url = otherEntity;
url = url.replace(/\/$/, "");
if (id)
return url + '/' + id;
else
return url;
}
},
link: function(scope, element, attrs, ngModel) {
scope.getMapsUrl = function(q)
{
if ((navigator.platform.indexOf('iPhone') != -1) || (navigator.platform.indexOf('iPad') != -1) || (navigator.platform.indexOf('iPod') != -1))
return 'http://maps.apple.com/?q=' + encodeURIComponent(q);
else
return 'https://maps.google.com/maps?q=' + encodeURIComponent(q);
}
scope.getTemplate = function() {
if (!scope.fieldLayoutData)
return '
';
// Preset dynamic field
if (typeof scope.fieldLayoutData.NgDynamicDirectives == 'string' &&
scope.fieldLayoutData.NgDynamicDirectives.indexOf('@') == 0)
{
// Remove 'format-' from NgDirectives and uppercase first letter.
//var type = scope.fieldLayoutData.NgDirectives.substring(7, scope.fieldLayoutData.NgDirectives.length);
//type = type.charAt(0).toUpperCase() + type.slice(1);
var type = '';
switch (scope.EffectiveNgDirectives)
{
case 'format-input':
type = 'Input';
break;
case 'format-currency':
type = 'Currency';
break;
case 'format-yesno':
type = 'YesNo';
break;
default:
type = '';
}
// Create alternative filed name: es. MyFieldValue in case of format-decimal become MyFieldValueDecimal
var alternativeFieldName = scope.fieldLayoutData.FieldName + type;
if (scope.entityData[alternativeFieldName] !== undefined)
scope.EffectiveFieldName = alternativeFieldName;
else
scope.EffectiveFieldName = scope.fieldLayoutData.FieldName;
// TEST
scope.EffectiveFieldName = scope.EffectiveFieldName;
// Digits
var alternativeFieldNameDigits = alternativeFieldName + 'Digits';
if (scope.entityData[alternativeFieldNameDigits] !== undefined && scope.entityData[alternativeFieldNameDigits] != null)
scope.EffectiveFieldNameDigits = scope.entityData[alternativeFieldNameDigits];
else
scope.EffectiveFieldNameDigits = scope.fieldLayoutData.NgDecimalDigits;
// Symbol
var alternativeFieldNameSymbol = alternativeFieldName + 'Symbol';
if (scope.entityData[alternativeFieldNameSymbol] !== undefined && scope.entityData[alternativeFieldNameSymbol] != null)
scope.EffectiveFieldNameSymbol = scope.entityData[alternativeFieldNameSymbol];
else
scope.EffectiveFieldNameSymbol = scope.fieldLayoutData.NgDecimalCurrencySymbol;
}
else
{
scope.EffectiveFieldName = scope.fieldLayoutData.FieldName;
scope.EffectiveNgDirectives = scope.fieldLayoutData.NgDirectives;
scope.EffectiveFieldNameSymbol = scope.fieldLayoutData.NgDecimalCurrencySymbol;
scope.EffectiveFieldNameDigits = scope.fieldLayoutData.NgDecimalDigits;
}
scope.EffectiveNgDecimalDigitsStepValue = Math.pow(10, scope.EffectiveFieldNameDigits * -1);
var templ =
'
';
if (scope.EffectiveNgDirectives != 'format-autocompletechips')
templ +=
'
';
if (scope.EffectiveNgDirectives == 'format-select')
templ +=
'
' +
' ' +
' {[{ entityData[EffectiveFieldName][fieldLayoutData.NgSelectEntityLabelField] }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-autocomplete')
templ +=
'
' +
' ' +
' ' +
' {[{ entityData[EffectiveFieldName][fieldLayoutData.NgAutocompleteEntityLabelField] | ifEmpty: \'n/d\'}]} ' +
' ' +
' ';
if (scope.EffectiveNgDirectives == 'format-autocompletechips')
templ +=
'
' +
' ' +
' ' +
' ' +
' {[{ obj[fieldLayoutData.NgAutocompleteEntityLabelField] | ifEmpty: \'n/d\'}]} ' +
' ' +
' ';
if (scope.EffectiveNgDirectives == 'format-duration')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] | durationFormatStd }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-time')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] | timeFormatStd }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-date')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] | dateFormatStd }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-datetime')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] | dateTimeFormatStd }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-recurrence')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] | recurrenceFormatStd }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-yesno')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] | trueFalseStd }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-decimal')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] | decimalStd : EffectiveFieldNameDigits }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-currency' && scope.EffectiveFieldNameSymbol != '%')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] | currencyStd : EffectiveFieldNameDigits : EffectiveFieldNameSymbol }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-currency' && scope.EffectiveFieldNameSymbol == '%')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] | currencyStd : EffectiveFieldNameDigits : EffectiveFieldNameSymbol }]} ' +
' ' +
'
' +
' ' +
'
';
if (scope.EffectiveNgDirectives == 'format-led')
templ +=
'
' +
'
';
if (scope.EffectiveNgDirectives == 'format-email')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-phone')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-map')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-input' || scope.EffectiveNgDirectives == 'format-multiline')
templ +=
'
' +
' {[{ entityData[EffectiveFieldName] }]} ' +
' ';
if (scope.EffectiveNgDirectives == 'format-color')
templ +=
'
' +
' ' +
' {[{ entityData[EffectiveFieldName] }]} ' +
' ';
templEnd =
'
';
return templ + templEnd;
};
if ($mdMedia)
scope.$mdMedia = $mdMedia;
if (attrs.name)
scope.name = attrs.name;
if (scope.fieldLayoutData.NgDynamicDirectives)
{
var dynDir = scope.fieldLayoutData.NgDynamicDirectives;
if (typeof dynDir == 'string' && dynDir.indexOf('@') == 0)
{
// Replace NgDirective with dynamic value
scope.NgDynamicDirectivesFieldName = dynDir.substring(1, dynDir.length);
}
}
var currentElement = element;
scope.$watch(function() {
if (scope.NgDynamicDirectivesFieldName)
{
return scope.entityData[scope.NgDynamicDirectivesFieldName];
}
//console.log("Watching: ", scope.fieldLayoutData.NgDirectives);
return scope.fieldLayoutData.NgDirectives;
}, function(newValue, oldValue) {
// You actions here
//console.log("I got the new value! ", newValue);
scope.EffectiveNgDirectives = newValue; // scope.entityData[scope.NgDynamicDirectivesFieldName];
var el = $compile(scope.getTemplate())(scope);
currentElement.replaceWith(el);
currentElement = el;
}, true);
// scope.$watch(function() {
// if (!scope.entityData)
// return 0;
// if (!scope.EffectiveNgDirectives)
// return null;
// else if (scope.EffectiveNgDirectives == 'format-select')
// {
// return scope.entityData.Id;
// }
// else return null;
// }, function(newValue, oldValue) {
// if (scope.entityData)
// {
// var el = $compile(scope.getTemplate())(scope);
// currentElement.replaceWith(el);
// currentElement = el;
// }
// }, true);
}
}
}
]);
t3_ng_app_index.directive('t3EditField', ['$mdMedia', '$compile', '$http', '$q',
function ($mdMedia, $compile) {
return {
require: '?ngModel',
replace: true,
template: '
',
scope: {
ngReadonly: "=ngReadonly",
showLabels: "=t3ShowLabels",
loginData: "=t3LoginData",
editboxForm: "=t3EditboxForm",
fieldLayoutData: "=t3FieldLayoutData",
entityLayoutData: "=t3EntityLayoutData",
entityData: "=t3EntityData"
},
controller: function($scope, $http, $q) {
var checkValues = [false, true, null];
var len = checkValues.length;
var index = 0;
/**
* SIGNATURE PAD
*/
$scope.signaturePadShow = function() {
document.getElementById("signature-pad-overlay").style.display = "block";
}
$scope.signaturePadOk = function() {
document.getElementById("signature-pad-overlay").style.display = "none";
}
$scope.signaturePadCancel = function() {
document.getElementById("signature-pad-overlay").style.display = "none";
}
$scope.isReadOnly = function() {
return ($scope.fieldLayoutData.NgReadOnly || $scope.ngReadonly);
}
$scope.getColor = function(obj, index)
{
if ($scope.entityData[$scope.fieldLayoutData.NgStatusColorFieldName] &&
$scope.entityData[$scope.fieldLayoutData.NgStatusColorFieldName] != '')
{
return $scope.entityData[$scope.fieldLayoutData.NgStatusColorFieldName][index];
}
else
{
return obj.Color;
}
}
$scope.checkBoxIsChecked = function(entity, fieldName) {
if (!entity || !fieldName)
return false;
return (entity[fieldName] == true);
}
$scope.checkBoxIsIndeterminated = function(entity, fieldName) {
if (!entity || !fieldName)
return true;
return (entity[fieldName] == null);
}
$scope.checkBoxModelChange = function(entity, fieldName) {
}
$scope.transformChip = function(chip, object, listField) {
if (!object)
return;
if (object && listField && !object[listField])
object[listField] = [];
// If it is an object, it's already a known chip
if (angular.isObject(chip)) {
for(i = 0 ; i < object[listField].length; i++)
if (angular.equals(object[listField][i]))
return;
return chip;
}
}
$scope.buildLinkToOtherEntityId = function(otherEntity, id) {
//var url = T3_APP_base_url + '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D';
var url = otherEntity;
url = url.replace(/\/$/, "");
if (id)
return url + '/' + id;
else
return url;
}
if ($scope.fieldLayoutData.NgDirectives == 'format-fixedselect')
{
if ($scope.fieldLayoutData.NgFixedSelectOptions)
{
$scope.fixedSelectOptions = JSON.parse($scope.fieldLayoutData.NgFixedSelectOptions);
}
}
if ($scope.fieldLayoutData.NgDirectives == 'format-select' ||
$scope.fieldLayoutData.NgDirectives == 'format-autocomplete' ||
$scope.fieldLayoutData.NgDirectives == 'format-autocompletechips')
{
$scope.applyHtmlEntityLayout = function(response) {
if (response)
{
$scope.t3_html_entity_layout = response;
return true;
}
return false;
}
// Get entity html field from APIs
$scope.getHtmlEntityLayout = function() {
var controllerName = null;
if ($scope.fieldLayoutData.NgAutocompleteControllerName)
controllerName = $scope.fieldLayoutData.NgAutocompleteControllerName;
if ($scope.fieldLayoutData.NgSelectControllerName)
controllerName = $scope.fieldLayoutData.NgSelectControllerName;
if (!controllerName)
return;
// T3_API_base_url + 'api/HtmlEntityLayouts/ByEntityName/\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D';
// controllerName = window['T3_API_' + controllerName.toUpperCase() + '_controller_name'];
// if (!controllerName)
// return;
var $method = 'GET';
var $url = T3_API_base_url + 'api/HtmlEntityLayouts/ByEntityName/' + controllerName;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: null
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
{
$scope.applyHtmlEntityLayout(decodeJsonReferences(data));
}
else
t3_ng_svc_exception.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_get_html_entity_layout_error, response, status);
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
t3_ng_svc_exception.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_get_html_entity_layout_error, response, status);
});
};
$scope.t3_html_entity_layout = null;
if ($scope.fieldLayoutData.NgDirectives == 'format-select')
{
// md-select
$scope.searchObject_select = {
SelectTop: 100,
ByPattern: '',
OrderBy: { FieldName: "SequenceNo", Direction: 0 },
Paging: null,
FastSearch: false,
SkipRecalculations: $scope.fieldLayoutData.NgSelectSkipRecalculations,
ShowHidden: false
};
if (T3_EN_FAST_SEARCH)
$scope.searchObject_select.FastSearch = true;
// Default value
$scope.fieldName = '\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D';
$scope.init_select = function(fieldName, filters, fastSearchFields)
{
// Define fieldname for the controller
if (fieldName)
{
$scope.fieldName = fieldName.toLowerCase();
}
// Init static filters
if (filters)
{
//This function is sort of private constructor for controller
if (typeof filters === 'string' || filters instanceof String)
$scope.filters = JSON.parse(filters);
else
$scope.filters = filters;
// Copy filters into searchObject
for(var i in $scope.filters) $scope.searchObject_select[i]=$scope.filters[i];
}
if (fastSearchFields)
{
//This function is sort of private constructor for controller
if (typeof fastSearchFields === 'string' || fastSearchFields instanceof String)
$scope.fastSearchFields = JSON.parse(fastSearchFields);
else
$scope.fastSearchFields = fastSearchFields;
// Copy filters into searchObject
if (!$scope.searchObject_select.FastSearchFields)
$scope.searchObject_select.FastSearchFields = [];
for(var i in $scope.fastSearchFields)
$scope.searchObject_select.FastSearchFields.push($scope.fastSearchFields[i]);
}
$scope.search_select();
};
$scope.searchResults_select = [];
$scope.search_select = function() {
// var cacheData = localStorage.t3_select_cache_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_data;
// var cacheTimestamp = localStorage.t3_select_cache_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_timestamp;
// if (!T3_DEBUG && cacheData && cacheTimestamp)
// {
// var cacheData = JSON.parse(cacheData);
// var cacheTimestamp = moment(JSON.parse(cacheTimestamp));
// if (moment().diff(cacheTimestamp, 'seconds') < 30)
// {
// $scope.searchResults_select = decodeJsonReferences(cacheData);
// return;
// }
// }
var controllerName = null;
if ($scope.fieldLayoutData.NgSelectControllerName)
controllerName = $scope.fieldLayoutData.NgSelectControllerName;
if (!controllerName)
return;
// T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_controller_name + '/Search';
controllerName = window['T3_API_' + controllerName.toUpperCase() + '_controller_name'];;
var $method = 'POST';
var $url = T3_API_base_url + 'api/' + controllerName + '/Search';
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: $scope.searchObject_select
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
{
//localStorage.setItem('t3_select_cache_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_data', JSON.stringify(data));
//localStorage.setItem('t3_select_cache_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_timestamp', JSON.stringify(moment()));
$scope.searchResults_select = decodeJsonReferences(data);
}
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status > 0)
t3_ng_svc_exception.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_search_error, response, status);
});
};
// [end] md-select
}
if ($scope.fieldLayoutData.NgDirectives == 'format-autocomplete' ||
$scope.fieldLayoutData.NgDirectives == 'format-autocompletechips')
{
// md-autocomplete
$scope.searchObject_autocomplete = {
SelectTop: 100,
ByPattern: '',
OrderBy: null,
Paging: null,
FastSearch: false,
SkipRecalculations: $scope.fieldLayoutData.NgAutocompleteSkipRecalculations,
ShowHidden: false
};
if (T3_EN_FAST_SEARCH)
$scope.searchObject_autocomplete.FastSearch = true;
// Default value
$scope.fieldName = $scope.fieldLayoutData.FieldName;
$scope.init_autocomplete = function(fieldName, filters, fastSearchFields)
{
// Define fieldname for the controller
if (fieldName)
{
$scope.fieldName = fieldName.toLowerCase();
}
// Init static filters
if (filters)
{
//This function is sort of private constructor for controller
if (typeof filters === 'string' || filters instanceof String)
$scope.filters = JSON.parse(filters);
else
$scope.filters = filters;
// Copy filters into searchObject
for(var i in $scope.filters) $scope.searchObject_autocomplete[i]=$scope.filters[i];
}
if (fastSearchFields)
{
//This function is sort of private constructor for controller
if (typeof fastSearchFields === 'string' || fastSearchFields instanceof String)
$scope.fastSearchFields = JSON.parse(fastSearchFields);
else
$scope.fastSearchFields = fastSearchFields;
// Copy filters into searchObject
if (!$scope.searchObject_autocomplete.FastSearchFields)
$scope.searchObject_autocomplete.FastSearchFields = [];
for(var i in $scope.fastSearchFields)
$scope.searchObject_autocomplete.FastSearchFields.push($scope.fastSearchFields[i]);
}
$scope.autocompleteSelectedItem = null;
};
$scope.$watch(function() {
if (!$scope.entityData || !$scope.fieldLayoutData || !$scope.fieldLayoutData.FieldName)
return null;
return $scope.entityData[$scope.fieldLayoutData.FieldName];
}, function(newSelectedItem) {
// HERE
if (!newSelectedItem)
$scope.searchObject_autocomplete.ByPattern = '';
$scope.autocompleteSelectedItem = newSelectedItem;
});
$scope.prepareDynamicFilters = function(entity)
{
if (!$scope.filters)
return true;
for(var i in $scope.filters)
{
if (typeof $scope.filters[i] == 'string' && $scope.filters[i].indexOf('@') == 0)
{
// Replace dinamic filter with entity specified field
$scope.searchObject_autocomplete[i]=entity[$scope.filters[i].substring(1, $scope.filters[i].length)];
}
else if (typeof $scope.filters[i] == 'string' && $scope.filters[i].indexOf('#') == 0)
{
// Replace dinamic filter with entity specified field
var value = entity[$scope.filters[i].substring(1, $scope.filters[i].length)];
if (value === undefined || value == null)
return false;
$scope.searchObject_autocomplete[i] = value;
}
else
{
$scope.searchObject_autocomplete[i]=$scope.filters[i];
}
}
return true;
}
$scope.searchResults_promise = null;
$scope.searchResults_autocomplete = [];
$scope.search_autocomplete = function(entity, relatedEntityField, relatedEntityKey, text, searchCallback) {
//if (!angular.isString(text))
// return;
// if (text === undefined || text == "")
// {
// $scope.select_autocomplete(entity, relatedEntityField, relatedEntityKey, null, true);
// return;
// }
var controllerName = null;
if ($scope.fieldLayoutData.NgAutocompleteControllerName)
controllerName = $scope.fieldLayoutData.NgAutocompleteControllerName;
if (!controllerName)
return;
controllerName = window['T3_API_' + controllerName.toUpperCase() + '_controller_name'];
var $method = 'POST';
var $url = T3_API_base_url + 'api/' + controllerName + '/Search';
if (!$scope.prepareDynamicFilters(entity))
return;
$scope.searchResults_promise = $http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: $scope.searchObject_autocomplete
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
{
$scope.searchResults_autocomplete = decodeJsonReferences(data);
if (searchCallback && typeof searchCallback === "function")
searchCallback($scope.searchResults_autocomplete);
return $scope.searchResults_autocomplete;
}
if ($scope.searchResults_promise)
$scope.searchResults_promise.resolve();
}).catch(function onError(response) {
// Handle error
var data = response.data;
if (!data)
data = [];
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status > 0)
t3_ng_svc_exception.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_search_error, response, status);
if ($scope.searchResults_promise)
$scope.searchResults_promise.resolve();
});
return $scope.searchResults_promise;
};
$scope.textChanged_autocomplete = function(entity, relatedEntityField, relatedEntityKey, text, searchCallback) {
if (!angular.isString(text))
return;
if (text === undefined || text == "")
{
$scope.select_autocomplete(entity, relatedEntityField, relatedEntityKey, null, true);
return;
}
}
$scope.select_autocomplete = function(entity, relatedEntityField, relatedEntityKey, relatedEntity, clearRequest) {
if (!entity)
return;
if (!relatedEntity && !clearRequest)
return;
if (clearRequest || !relatedEntity)
{
$scope.searchObject_autocomplete.ByPattern = '';
entity[relatedEntityField] = null;
entity[relatedEntityKey] = null;
// onUnLink event
if ($scope.$parent !== undefined && typeof $scope.onUnLink_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D == 'function') {
$scope.$parent['onUnLink_' + $scope.fieldName](entity, relatedEntityField, relatedEntityKey, relatedEntity);
}
}
if (relatedEntity)
{
entity[relatedEntityField] = relatedEntity;
entity[relatedEntityKey] = relatedEntity.Id;
// onLink event
if ($scope !== undefined && typeof $scope['onLink_' + $scope.fieldName] == 'function') {
$scope['onLink_' + $scope.fieldName](entity, relatedEntityField, relatedEntityKey, relatedEntity);
}
// onLink event
else if ($scope.$parent !== undefined && typeof $scope.$parent['onLink_' + $scope.fieldName] == 'function') {
$scope.$parent['onLink_' + $scope.fieldName](entity, relatedEntityField, relatedEntityKey, relatedEntity);
}
else if ($scope.$parent.$parent !== undefined && typeof $scope.$parent.$parent['onLink_' + $scope.fieldName] == 'function') {
$scope.$parent.$parent['onLink_' + $scope.fieldName](entity, relatedEntityField, relatedEntityKey, relatedEntity);
}
}
};
}
if ($scope.fieldLayoutData.NgDirectives == 'format-autocomplete')
{
// Fire get field html layout
$scope.getHtmlEntityLayout();
$scope.init_autocomplete($scope.fieldLayoutData.FieldName, $scope.fieldLayoutData.NgAutocompleteFilter, $scope.fieldLayoutData.NgAutocompleteFastSearchFields);
}
if ($scope.fieldLayoutData.NgDirectives == 'format-autocompletechips')
{
// Fire get field html layout
$scope.getHtmlEntityLayout();
$scope.init_autocomplete($scope.fieldLayoutData.FieldName, $scope.fieldLayoutData.NgAutocompleteFilter);
}
if ($scope.fieldLayoutData.NgDirectives == 'format-select')
{
// Fire get field html layout
$scope.getHtmlEntityLayout();
$scope.init_select($scope.fieldLayoutData.FieldName, $scope.fieldLayoutData.NgSelectFilter, $scope.fieldLayoutData.NgSelectFastSearchFields);
}
}
},
link: function(scope, element, attrs, ngModel) {
scope.getTemplate = function() {
if (!scope.fieldLayoutData)
return '
';
// Preset dynamic field
if (typeof scope.fieldLayoutData.NgDynamicDirectives == 'string' &&
scope.fieldLayoutData.NgDynamicDirectives.indexOf('@') == 0)
{
// Remove 'format-' from NgDirectives and uppercase first letter.
//var type = scope.fieldLayoutData.NgDirectives.substring(7, scope.fieldLayoutData.NgDirectives.length);
//type = type.charAt(0).toUpperCase() + type.slice(1);
var type = '';
switch (scope.EffectiveNgDirectives)
{
case 'format-input':
type = 'Input';
break;
case 'format-currency':
type = 'Currency';
break;
case 'format-yesno':
type = 'YesNo';
break;
default:
type = '';
}
// Create alternative filed name: es. MyFieldValue in case of format-decimal become MyFieldValueDecimal
var alternativeFieldName = scope.fieldLayoutData.FieldName + type;
if (scope.entityData[alternativeFieldName] !== undefined)
scope.EffectiveFieldName = alternativeFieldName;
else
scope.EffectiveFieldName = scope.fieldLayoutData.FieldName;
// TEST
scope.EffectiveFieldName = scope.EffectiveFieldName;
// Digits
var alternativeFieldNameDigits = alternativeFieldName + 'Digits';
if (scope.entityData[alternativeFieldNameDigits] !== undefined && scope.entityData[alternativeFieldNameDigits] != null)
scope.EffectiveFieldNameDigits = scope.entityData[alternativeFieldNameDigits];
else
scope.EffectiveFieldNameDigits = scope.fieldLayoutData.NgDecimalDigits;
// Symbol
var alternativeFieldNameSymbol = alternativeFieldName + 'Symbol';
if (scope.entityData[alternativeFieldNameSymbol] !== undefined && scope.entityData[alternativeFieldNameSymbol] != null)
scope.EffectiveFieldNameSymbol = scope.entityData[alternativeFieldNameSymbol];
else
scope.EffectiveFieldNameSymbol = scope.fieldLayoutData.NgDecimalCurrencySymbol;
}
else
{
scope.EffectiveFieldName = scope.fieldLayoutData.FieldName;
scope.EffectiveNgDirectives = scope.fieldLayoutData.NgDirectives;
scope.EffectiveFieldNameSymbol = scope.fieldLayoutData.NgDecimalCurrencySymbol;
scope.EffectiveFieldNameDigits = scope.fieldLayoutData.NgDecimalDigits;
}
scope.EffectiveNgDecimalDigitsStepValue = Math.pow(10, scope.EffectiveFieldNameDigits * -1);
var templ =
'
';
return templ + templEnd;
};
if ($mdMedia)
scope.$mdMedia = $mdMedia;
if (attrs.name)
scope.name = attrs.name;
if (scope.fieldLayoutData.NgDynamicDirectives)
{
var dynDir = scope.fieldLayoutData.NgDynamicDirectives;
if (typeof dynDir == 'string' && dynDir.indexOf('@') == 0)
{
// Replace NgDirective with dynamic value
scope.NgDynamicDirectivesFieldName = dynDir.substring(1, dynDir.length);
}
}
var currentElement = element;
scope.$watch(function() {
if (scope.NgDynamicDirectivesFieldName)
{
return scope.entityData[scope.NgDynamicDirectivesFieldName];
}
//console.log("Watching: ", scope.fieldLayoutData.NgDirectives);
return scope.fieldLayoutData.NgDirectives;
}, function(newValue, oldValue) {
// You actions here
//console.log("I got the new value! ", newValue);
scope.EffectiveNgDirectives = newValue; // scope.entityData[scope.NgDynamicDirectivesFieldName];
// OLD
//var el = $compile(scope.getTemplate())(scope);
//currentElement.replaceWith(el);
// NEW
var el = $(scope.getTemplate());
currentElement.replaceWith(el);
currentElement = el;
$compile(currentElement)(scope);
}, true);
// scope.$watch(function() {
// if (!scope.entityData)
// return 0;
// if (!scope.EffectiveNgDirectives)
// return null;
// else if (scope.EffectiveNgDirectives == 'format-select')
// {
// return scope.entityData.Id;
// }
// else return null;
// }, function(newValue, oldValue) {
// if (newValue && scope.entityData)
// {
// var el = $compile(scope.getTemplate())(scope);
// currentElement.replaceWith(el);
// currentElement = el;
// }
// }, true);
}
}
}
]);
t3_ng_app_index.directive('serverValidate', [
function () {
return {
restrict: 'A',
require: 'form',
link: function ($scope, $elem, $attrs, form) {
var setFieldInvalid = function (field, errorType, errorMessage) {
// var changeListener = function () {
// field.$setValidity(errorType, true);
// var index = field.$viewChangeListeners.indexOf(changeListener);
// if (index > -1) {
// field.$viewChangeListeners.splice(index, 1);
// }
// };
field.$setTouched();
field.$error.message = errorMessage;
//field.$viewChangeListeners.push(changeListener);
field.$setDirty();
field.$setValidity(errorType, false);
};
var setFieldValid = function (field, errorType, errorMessage) {
// var changeListener = function () {
// field.$setValidity(errorType, true);
// var index = field.$viewChangeListeners.indexOf(changeListener);
// if (index > -1) {
// field.$viewChangeListeners.splice(index, 1);
// }
// };
//field.$setTouched();
field.$error = {};
//field.$viewChangeListeners.push(changeListener);
//field.$setPristine();
field.$setValidity(errorType, true);
};
$scope.$watch('serverErrors', function (errors) {
if (!errors || errors.length <= 0)
{
for (var property in form) {
if (!property.startsWith('$'))
{
setFieldValid(form[property], 'server.custom');
}
}
}
else
{
angular.forEach(errors, function (error) {
if (error.field in form) {
setFieldInvalid(form[error.field], 'server.' + error.type, error.message);
}
});
}
});
}
};
}
]);
t3_ng_app_index.directive('t3Focus', function($timeout) {
return function(scope, element, attrs) {
scope.$watch(attrs.t3Focus,
function (newValue) {
$timeout(function() {
newValue && element[0].focus();
scope[attrs.t3Focus] = false;
}, 500);
},true);
};
});
t3_ng_app_index.directive('t3FocusTwo', function($timeout) {
return {
// scope: {
// t3FocusTwo: '@'
// },
link: function(scope, element, attrs) {
function doFocus() {
$timeout(function() {
element[0].focus();
});
}
scope.t3FocusTwo = attrs.t3FocusTwo;
//attrs.$observe('t3FocusTwo', function() {
scope.$watch(scope.t3FocusTwo, function() {
if (scope.$eval(scope.t3FocusTwo))
doFocus();
});
// focus if attribute value changes to 'true'
//attrs.$watch(attrs.t3FocusTwo, function(value) {
// if (value === 'true') {
// doFocus();
// }
//});
//}
}
}
});
t3_ng_app_index.directive('focusIf', function($timeout) {
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
var dom = $element[0];
if ($attrs.focusIf) {
$scope.$watch($attrs.focusIf, focus);
} else {
focus(true);
}
function focus(condition) {
if (condition) {
$timeout(function() {
dom.focus();
}, $scope.$eval($attrs.focusDelay) || 0);
}
}
}
};
});
// Include other directives
t3_ng_app_index.filter('cut', function () {
return function (value, wordwise, max, tail) {
if (!value) return '';
max = parseInt(max, 10);
if (!max) return value;
if (value.length <= max) return value;
value = value.substr(0, max);
if (wordwise) {
var lastspace = value.lastIndexOf(' ');
if (lastspace != -1) {
//Also remove . and , so its gives a cleaner result.
if (value.charAt(lastspace-1) == '.' || value.charAt(lastspace-1) == ',') {
lastspace = lastspace - 1;
}
value = value.substr(0, lastspace);
}
}
return value + (tail || ' …');
};
});
t3_ng_app_index.filter('durationFormatStd', function($filter) {
return function(input)
{
if(input == null) { return "n/d"; }
var locale = window.navigator.userLanguage || window.navigator.language;
moment.locale(locale);
var s = '';
var m = moment.duration(input);
var asHours = m.asHours();
if (asHours < 0)
{
s = '- ';
asHours = asHours * -1;
}
var hours = Math.floor(asHours);
var minutes = m.minutes();
var seconds = m.seconds();
var milliseconds = m.milliseconds();
s += Math.abs(hours) + 'h ';
s += ("0" + Math.abs(minutes)).slice(-2) + 'm';
if (seconds != 0)
s += ("0" + Math.abs(seconds)).slice(-2) + 's';
/**
if (hours != 0)
s += Math.abs(hours) + 'h ';
if (minutes != 0)
s += Math.abs(minutes) + 'min ';
if (seconds != 0)
s += Math.abs(seconds) + 's ';*/
//if (milliseconds > 0)
// s += milliseconds + 'ms ';
if (s == '')
return "0s";
else
return s;
};
});
t3_ng_app_index.filter('timeFormatStd', function($filter) {
return function(input)
{
if(input == null) { return "n/d"; }
//var locale = window.navigator.userLanguage || window.navigator.language;
//moment.locale(locale);
var m = moment.utc(input).format('LT');
return m;
};
});
t3_ng_app_index.filter('dateFormatStd', function($filter) {
return function(input)
{
if(input == null) { return "n/d"; }
var locale = window.navigator.userLanguage || window.navigator.language;
moment.locale(locale);
var m = moment(input).format('L');
return m;
};
});
t3_ng_app_index.filter('dateTimeFormatStd', function($filter) {
return function(input)
{
if(input == null) { return "n/d"; }
var locale = window.navigator.userLanguage || window.navigator.language;
moment.locale(locale);
var m = moment(input).format('LLL');
return m;
};
});
t3_ng_app_index.filter('recurrenceFormatStd', function($filter) {
return function(input)
{
if(input == null) { return "Nessuna"; }
if(input == 'none') { return "Eliminato"; }
if(input == '') { return "Variazione"; }
var extra = null;
var type = null;
var hasType = false;
var count = null;
var hasCount = false;
var dayAndCount2 = null;
var hasDayAndCount2 = false;
var days = null;
var hasDays = false;
var weekDays = [];
var hasWeekDays = false;
if (input.indexOf('#') > -1)
{
var tokens0 = input.split('#', 2);
input = tokens0[0]
extra = tokens0[1];
}
var tokens = input.split('_', 5);
if (tokens.length >= 1)
{
type = tokens[0];
hasType = true;
}
if (tokens.length >= 2 && tokens[1] != '')
{
count = Number(tokens[1]);
hasCount = true;
}
if (tokens.length >= 3 && tokens[2] != '')
{
dayAndCount2 = Number(tokens[2]);
hasDayAndCount2 = true;
}
if (tokens.length >= 4)
{
days = tokens[3];
hasDays = true;
}
if (tokens.length >= 5)
{
if (tokens[4].indexOf(',') > -1)
{
var tokens1 = tokens[4].split(',', 7);
var sourceWeekDays = [ 'dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab' ];
for (var i = 0; i < tokens1.length; i++)
{
if (tokens1[i] && tokens1[i] != '')
{
var val = Number(tokens1[i]);
if (val >= 0 && val <= 6)
{
weekDays.push(sourceWeekDays[val]);
hasWeekDays = true;
}
}
}
}
}
var result = '';
if (hasType && hasCount)
{
switch (type)
{
case 'day':
if (count > 1)
result = 'Ogni ' + count + ' giorni'
else
result = 'Ogni giorno';
break;
case 'week':
if (count > 1)
result = 'Ogni ' + count + ' settimane'
else
result = 'Ogni settimana';
break;
case 'month':
if (count > 1)
result = 'Ogni ' + count + ' mesi'
else
result = 'Ogni mese';
break;
case 'year':
if (count > 1)
result = 'Ogni ' + count + ' anni'
else
result = 'Ogni anno';
break;
default:
result = 'n/d';
return;
}
if (hasDays && hasDayAndCount2)
{
if (dayAndCount2 == '7')
result += ' la ';
else
result += ' il ';
}
if (hasDays && days > 0)
{
result += days + '^ ';
}
if (hasDayAndCount2)
{
switch (dayAndCount2)
{
case 1:
result += 'lunedì';
break;
case 2:
result += 'martedì';
break;
case 3:
result += 'mercoledì';
break;
case 4:
result += 'giovedì';
break;
case 5:
result += 'venerdì';
break;
case 6:
result += 'sabato';
break;
case 7:
result += 'domenica';
break;
default:
result += '';
}
}
}
if (hasWeekDays)
{
result += ' (';
first = true;
for (var i = 0; i < weekDays.length; i++)
{
if (!first)
result += ',';
else
first = false;
result += weekDays[i]
first = false;
}
result += ')';
}
return result;
};
});
t3_ng_app_index.filter('trueFalseStd', function() {
return function(text, length, end) {
if (text) {
return 'Sì';
}
return 'No';
}
});
t3_ng_app_index.filter('ifEmpty', function() {
return function(input, defaultValue) {
if (angular.isUndefined(input) || input === null || input === '') {
return defaultValue;
}
return input;
}
});
t3_ng_app_index.filter('decimalStd', function() {
return function(input, decimalDigits, unitSymbol, decimalSeparator, thousandSeparator) {
var custom_unitSymbol = "";
var custom_decimalDigits = 2;
var custom_decimalSeparator = ",";
var custom_thousandSeparator = ".";
formatMoney = function(n, c, d, t, b) {
c = isNaN(c = Math.abs(c)) ? custom_decimalDigits : c;
d = d == undefined ? custom_decimalSeparator : d;
t = t == undefined ? custom_thousandSeparator : t;
b = b == undefined ? custom_unitSymbol : b;
var s = n < 0 ? "-" : "",
i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c)));
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "") + " " + b;
};
return formatMoney(input, decimalDigits, decimalSeparator, thousandSeparator, unitSymbol);
}
});
t3_ng_app_index.filter('currencyStd', function() {
return function(input, decimalDigits, currencySymbol, decimalSeparator, thousandSeparator) {
var custom_currencySymbol = "€";
var custom_decimalDigits = 2;
var custom_decimalSeparator = ",";
var custom_thousandSeparator = ".";
formatMoney = function(n, c, d, t, b) {
c = isNaN(c = Math.abs(c)) ? custom_decimalDigits : c;
d = d == undefined ? custom_decimalSeparator : d;
t = t == undefined ? custom_thousandSeparator : t;
b = b == undefined ? custom_currencySymbol : b;
var s = n < 0 ? "-" : "",
i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c)));
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "") + " " + b;
};
return formatMoney(input, decimalDigits, decimalSeparator, thousandSeparator, currencySymbol);
}
});
// Used by code to redirect user to a page
t3_ng_app_index.factory('t3_ng_svc_go', function ($window) {
return {
go: function (page, id, backtopage, backtoid) {
// If user comes back to this page it shows the current entity
if (backtopage && backtoid !== undefined && backtoid !== null)
localStorage.setItem('t3_' + backtopage.toLowerCase() + '_go_to_id', backtoid);
if (id !== undefined && id !== null)
localStorage.setItem('t3_' + page.toLowerCase() + '_go_to_id', id);
else
localStorage.removeItem('t3_' + page.toLowerCase() + '_go_to_id');
$window.location.href = T3_APP_base_url + page;
}
};
});
// Used by code to redirect user to a page
t3_ng_app_index.factory('t3_ng_svc_go_back', function ($window) {
return {
goBack: function () {
$window.history.back();
}
};
});
// Exception handling code
t3_ng_app_index.factory('t3_ng_svc_exception', function ($window) {
return {
exception: function (message, data, httpstatus) {
console.log(data);
// Check for permission error (\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D model error)
if (data && data.ModelState && data.ModelState.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D && data.ModelState.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D[0])
{
alert(data.ModelState.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D[0]);
return;
}
localStorage.setItem('t3_last_error_httpstatuscode', httpstatus);
localStorage.setItem('t3_last_error_entity', '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D');
localStorage.setItem('t3_last_error_message', message);
localStorage.setItem('t3_last_error_data', JSON.stringify(data));
localStorage.setItem('t3_last_error_javascriptstack', new Error().stack);
if (httpstatus && httpstatus == 401)
{
localStorage.setItem('t3_redirect_after_login', '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D');
$window.location.href = T3_APP_base_url + 'index.html';
return;
}
if (!T3_DEBUG)
$window.location.href = T3_APP_base_url + 'error.html';
}
};
});
var t3_ng_app_index_config_done = true;
}
// Include other services
t3_ng_ctr_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_detail_views_dialog = function($scope, $mdDialog, $mdMedia, $q, title, dataRow, loginData, html_field_layout, html_detailfield_layout, Fullscreen)
{
$scope.title = title;
$scope.dataRow = dataRow;
$scope.loginData = loginData;
$scope.html_field_layout = html_field_layout;
$scope.html_detailfield_layout = html_detailfield_layout;
$scope.hide = function()
{
$mdDialog.hide();
};
$scope.cancel = function()
{
$mdDialog.cancel();
};
$scope.answer = function(answer)
{
$mdDialog.hide({ entity: $scope.entity, answer: answer });
};
};
// Include other controllers
function FormDialog_DialogController($scope, $mdDialog, $http, title, entity, layout, loginData) {
if (!entity || !layout)
return;
$scope.title = title;
$scope.EntityData = entity;
$scope.EntityFieldLayout = layout;
$scope.loginData = loginData;
$scope.isReadOnly = function(layoutMaster, entityMaster, layoutDetail, entityDetail, locaitonInfoString)
{
if ($scope.htmlEntityGrants && $scope.htmlEntityGrants.IsGod)
return false;
var res =
(layoutMaster && layoutMaster.ReadOnlyEntity) ||
(entityMaster && entityMaster.EntityReadOnly) ||
(layoutDetail && layoutDetail.ReadOnlyEntity) ||
(entityDetail && entityDetail.EntityReadOnly);
return res;
}
$scope.hide = function() {
$mdDialog.hide();
};
$scope.cancel = function() {
$mdDialog.cancel();
};
$scope.answer = function(answer)
{
if (answer)
{
$mdDialog.hide(answer);
}
else
$mdDialog.cancel();
};
}
t3_ng_app_index.controller("t3_ng_ctr_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D", function($scope, $window, $http,
$mdDialog, $mdToast, $mdMedia, $mdBottomSheet, $timeout, $interval, $location, $mdSidenav,
$log, $rootScope, $q,
// List of controller services built by Symfony PageController
t3_ng_svc_go , t3_ng_svc_go_back , t3_ng_svc_login , t3_ng_svc_exception
)
{
$scope.$mdMedia = $mdMedia;
$scope.layoutReady = false;
$rootScope.$on('$locationChangeSuccess', function (event, newUrl, oldUrl) {
if (newUrl === oldUrl)
{
event.preventDefault();
//return;
}
if (T3_DEBUG)
console.log('$on($locationChangeSuccess)');
var url = $location.path().split('/');
var url_lastToken = url[url.length - 1];
var url_penultimateToken = url[url.length - 2];
if (url_lastToken == '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D')
{
// search result
$scope.switchOnSearchMode(true);
if ($scope.layoutReady)
if (!$scope.searching)
$scope.search();
}
else
{
// is numeric
var number = parseFloat(url_lastToken);
if (!isNaN(number) && isFinite(number) && url_penultimateToken == '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D')
{
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData || $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id != number)
{
$scope.searching = true;
$scope.switchOnSearchMode(false);
$scope.selectById(url_lastToken, function() {
// Commit id found
$scope.searching = false;
}, function () {
// Rollback id not found
$scope.switchOnSearchMode(true);
if (!$scope.searching)
{
$scope.search();
$scope.searching = false;
}
});
}
}
else
{
var url = $location.path();
url = url.replace(/^\/|\/$/g, ''); // Remove beggining /
url = url.replace(/\/$/, ""); // Remove ending /
// change page
t3_ng_svc_go.go(url);
}
}
});
// Suspended
// window.onbeforeunload = function(e) {
// if ($scope.showEditBox)
// {
// e.preventDefault();
// return '';
// }
// };
$scope.buildLinkToId = function(id) {
//var url = T3_APP_base_url + '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D';
var url = '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D';
url = url.replace(/\/$/, ""); // Remove ending /
if (id)
return url + '/' + id;
else
return url;
}
$scope.buildLinkToOtherEntityId = function(otherEntity, id) {
//var url = T3_APP_base_url + '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D';
var url = otherEntity;
url = url.replace(/\/$/, "");
if (id)
return url + '/' + id;
else
return url;
}
$scope.getT3String = function(name)
{
var str = window[name];
if (str)
return str;
else
return 'n/d';
}
// Two times logout
$scope.logout1stClick = false;
$scope.logout = function(istantLogout){
if ($scope.logout1stClick || istantLogout)
{
$scope.loginData.token == null;
$scope.loginData = {
username: '',
password: '',
token: '',
expireDate: null
};
sessionStorage.setItem('t3_ng_login_data', $scope.loginData);
localStorage.setItem('t3_ng_login_data', $scope.loginData);
sessionStorage.clear();
localStorage.clear();
localStorage.setItem('t3_redirect_after_login', '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D');
$scope.t3_ng_svc_go.go('index.html');
}
else
{
$scope.logout1stClick = true;
setTimeout(function(){
$scope.logout1stClick = false;
$scope.$apply();
}, 15000);
}
}
// Change page tool
//$scope.changePageInfo = {
// HtmlEntityLayout: null,
// HtmlEntityLayoutId: null
//};
$scope.changePageSearchBoxVisible = false;
$scope.setPageSearchBoxVisible = function(forceValue)
{
if (forceValue !== undefined)
{
$scope.changePageSearchBoxVisible = forceValue;
if (forceValue)
{
setTimeout(function(){
$scope.changePageSearchBoxVisible = false;
$scope.$apply();
}, 10000);
}
}
return $scope.changePageSearchBoxVisible;
}
// AddressBook tool
$scope.addressBookInfo = {
AddressBook: null,
AddressBookId: null
};
$scope.addressBookSearchBoxVisible = false;
$scope.setAddressBookSearchBoxVisible = function(forceValue)
{
if (forceValue !== undefined)
{
$scope.addressBookSearchBoxVisible = forceValue;
}
return $scope.addressBookSearchBoxVisible;
}
$scope.composeEmail = function(address) {
$window.open("mailto:" + address,"_self");
};
$scope.startCall = function(number) {
$window.open("tel:" + number,"_self");
};
$scope.exception = function (message, data, httpstatus) {
console.log(data);
// Check for permission error (\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D model error)
if (data && data.ModelState && data.ModelState.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D && data.ModelState.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D[0])
{
$scope.showErrorToast(data.ModelState.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D[0]);
return;
}
localStorage.setItem('t3_last_error_httpstatuscode', httpstatus);
localStorage.setItem('t3_last_error_entity', '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D');
localStorage.setItem('t3_last_error_message', message);
localStorage.setItem('t3_last_error_data', JSON.stringify(data));
localStorage.setItem('t3_last_error_javascriptstack', new Error().stack);
if (httpstatus && httpstatus == 401)
{
localStorage.setItem('t3_redirect_after_login', '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D');
$window.location.href = T3_APP_base_url + 'index.html';
return;
}
if (!T3_DEBUG)
$window.location.href = T3_APP_base_url + 'error.html';
}
$scope.showSuccessToast = function(msg) {
$mdToast.show(
$mdToast.simple()
.textContent(msg)
.position('bottom')
.theme('success-toast')
.hideDelay(3000)
);
};
$scope.showWarningToast = function(msg) {
$mdToast.show(
$mdToast.simple()
.textContent(msg)
.position('bottom')
.theme('warning-toast')
.hideDelay(3000)
);
};
$scope.showErrorToast = function(msg) {
$mdToast.show(
$mdToast.simple()
.textContent(msg)
.position('bottom')
.theme('error-toast')
.hideDelay(3000)
);
};
$scope.getGlobalVariable = function(varName) {
return $window[varName];
}
$scope.t3_ng_svc_go = t3_ng_svc_go;
$scope.t3_ng_svc_go_back = t3_ng_svc_go_back;
$scope.loginData = t3_ng_svc_login;
//
// Login renew function
// > Il token is expiring renew it
// > If token is expired renew it and reload page
//
$scope.renewLogin = function() {
$http({
method: 'POST',
url: T3_API_LOGIN_token_url,
headers: T3_API_unauthorized_request_headers('application/x-www-form-urlencoded'),
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: {
username: $scope.loginData.username,
password: $scope.loginData.password,
grant_type: 'password'
}
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.loginData.expireDate = new Date(new Date().getTime() + (10000 * data.expires_in) - 48 * 3600000);
$scope.loginData.token = data.access_token;
sessionStorage.setItem('t3_ng_login_data', JSON.stringify($scope.loginData));
localStorage.setItem('t3_ng_login_data', JSON.stringify($scope.loginData));
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
alert(T3_NG_LOGIN_login_error + '\n\n' + (data ? data.error_description : ''));
$window.location.reload();
});
};
$scope.renewLoginLoop = function() {
if (!$scope.loginData || !$scope.loginData.username || !$scope.loginData.password || !$scope.loginData.token || !$scope.loginData.expireDate)
$window.location.href = T3_APP_base_url;
if (new Date() > new Date($scope.loginData.expireDate))
$scope.renewLogin();
setTimeout(function() { $scope.renewLoginLoop(); }, 10000); // Repeat every 10 seconds
}
$scope.renewLoginLoop(); // Loop activation
$scope.htmlEntityGrants = undefined;
$scope.selectHtmlEntityGrants = function(entityName) {
$method = 'GET';
$url = T3_API_HTMLENTITYGRANT_select_url + '/' + entityName;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token)
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
{
$scope.htmlEntityGrants = decodeJsonReferences(data);
}
$scope.modelChangeInProgress = false;
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.htmlEntityGrants = undefined;
if (status > 0)
$scope.exception(T3_NG_HTMLENTITYGRANT_select_error, response, status);
});
};
$scope.selectHtmlEntityGrants('\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D');
$scope.remoteControl = undefined;
$scope.disableRemoteControl = false;
$scope.selectRemoteControl = function(entityName) {
$method = 'GET';
$url = T3_API_REMOTECONTROL_select_url + '/' + entityName;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token)
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
{
$scope.remoteControl = decodeJsonReferences(data);
$scope.updateRemoteControl_ShowCommandBar($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_command_layout);
}
$scope.modelChangeInProgress = false;
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.remoteControl = undefined;
if (status > 0)
$scope.exception(T3_NG_REMOTECONTROL_select_error, response, status);
});
};
$scope.selectRemoteControl('\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D');
$scope.getRemoteControlMessage = function(commandName) {
var cmd = null;
var commands = $scope.remoteControl.AvailableCommands;
for (var i = 0; i < commands.length; i++)
{
if (commands[i].Name == commandName)
{
cmd = commands[i];
break;
}
}
return cmd;
}
$scope.EntityCheckedAll = false;
$scope.EntityCheckedAllChange = function(val)
{
if (val != undefined)
$scope.EntityCheckedAll = val;
for (var i = 0; i < $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.length; i++)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults[i].EntityChecked = $scope.EntityCheckedAll;
}
$scope.sendMultipleRemoteControlMessage = function(cmd)
{
var tmpCmd = cmd;
if (typeof tmpCmd == 'string')
var tmpCmd = $scope.getRemoteControlMessage(tmpCmd);
if (!tmpCmd)
return;
var confirm = $mdDialog.confirm()
.title("Confermi l'applicazione del comando multiplo " + tmpCmd.Text + " alla selezione?")
.ariaLabel(T3_NG_confirm_save)
.ok(T3_NG_confirm_save_yes)
.cancel(T3_NG_confirm_save_no);
$mdDialog.show(confirm).then(function() {
var tmr = null;
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults)
return;
var results = [];
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.sessions)
results = $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.sessions; // Scheduler mode
else
results = $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults;
for (var i = 0; i < results.length; i++)
{
if (results[i].EntityChecked)
{
$scope.sendRemoteControlMessage(results[i], cmd, function(updatedEntity, newEntity)
{
if (updatedEntity)
{
for (var j = 0; j < results.length; j++)
if (updatedEntity.Id == results[j].Id)
results[j] = updatedEntity;
}
});
}
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.sessions) // Scheduler mode
{
if (tmr)
clearTimeout(tmr);
tmr = setTimeout(function() {
$scope.search({callback: function (results) {
$scope.showFeedbackMessage(T3_NG_data_saved);
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.sessions) // Scheduler mode
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.lastUpdate = new Date();
}});
}, 1500);
}
else
{
if (tmr)
clearTimeout(tmr);
tmr = setTimeout(function() {
$scope.showFeedbackMessage(T3_NG_data_saved);
}, 1500);
}
}
//$scope.showFeedbackMessage(T3_NG_data_saved);
}, function() { });
}
$scope.preparingToSendRemoteControlMessage = function(entity, remoteControlMessage, commitCallback)
{
if (commitCallback && typeof commitCallback === "function")
commitCallback(remoteControlMessage);
}
$scope.toastRemoteControlMessageResponse = function(data)
{
if (data)
{
if (data.Error)
{
if (data.ErrorMessage)
{
$scope.showFeedbackMessage(data.ErrorMessage, 'error');
}
else
{
$scope.showFeedbackMessage(T3_NG_cmd_error);
}
}
else if (data.Warning)
{
if (data.WarningMessage)
{
$scope.showFeedbackMessage(data.WarningMessage, 'warning');
}
else
{
$scope.showFeedbackMessage(T3_NG_cmd_ok);
}
}
else if (data.Information)
{
if (data.InformationMessage)
{
$scope.showFeedbackMessage(data.InformationMessage, 'information');
}
else
{
$scope.showFeedbackMessage(T3_NG_cmd_ok);
}
}
else
{
$scope.showFeedbackMessage(T3_NG_cmd_ok);
}
}
}
$scope.sendRemoteControlMessage = function(entity, cmd, commitCallback, rollbackCallback) {
if (!cmd)
return;
if (typeof cmd == 'string')
var cmd = $scope.getRemoteControlMessage(cmd);
//$scope.searching = true;
$scope.disableRemoteControl = true;
$scope.serverErrors = [];
var $method = 'PUT';
var $url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_remote_control_message_url;
var data = $scope.remoteControl.RemoteControlMessageTemplate;
data['\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DRemoteControlCommand'] = cmd;
$scope.preparingToSendRemoteControlMessage(entity, data, function(remoteControlMessage) {
if (entity && entity.Id)
$url = $url + '/' + entity.Id;
else if (remoteControlMessage && remoteControlMessage.Id)
$url = $url + '/' + remoteControlMessage.Id;
else
return;
$scope.refresh2LastUpdateAt = null;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: encodeJsonReferences(remoteControlMessage)
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.refresh2LastUpdateAt = Date.now();
data = decodeJsonReferences(data);
if (data.Label)
{
$scope.printLabel(data.Label);
}
if (data.PrintedPdfInternalFilename)
{
$window.open(T3_API_ATTACHMENT_download_url + '/' + data.PrintedPdfInternalFilename, '_blank');
}
if (data.RefreshRequired)
{
$scope.searching = false;
$scope.disableRemoteControl = false;
$scope.search();
}
else if (data.UpdatedEntity)
{
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults)
{
for (var j = 0; j < $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.length; j++)
if (data.UpdatedEntity.Id == $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults[j].Id)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults[j] = data.UpdatedEntity;
}
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData && data.UpdatedEntity.Id == $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = data.UpdatedEntity;
$scope.searching = false;
$scope.disableRemoteControl = false;
}
else if (data.NewEntity)
{
// Future implementation
$scope.searching = false;
$scope.disableRemoteControl = false;
}
else
{
$scope.searching = false;
$scope.disableRemoteControl = false;
}
if (commitCallback && typeof commitCallback === "function")
{
if (!data || data.Error || data.Warning)
$scope.toastRemoteControlMessageResponse(data);
if (data)
// No information toast
commitCallback(data.UpdatedEntity, data.NewEntity);
else
rollbackCallback(data);
}
else
{
$scope.toastRemoteControlMessageResponse(data);
}
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status > 0)
$scope.showErrorToast(data.Message);
//$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_save_error, response, status);
//$scope.searching = false;
$scope.disableRemoteControl = false;
});
})
}
// If not logged in and skip page ng code and go to login page
if (!T3_DEBUG && ($scope.loginData.token == null || $scope.loginData.token == ''))
{
$scope.t3_ng_svc_go.go('index.html');
}
else
{
$scope.updateRemoteControl_ShowCommandBar = function(cmdLayout)
{
if (!$scope.remoteControl || !cmdLayout)
return;
$scope.remoteControl.ShowCommandBar = false;
for (i = 0; i < cmdLayout.length; i++) {
if (!cmdLayout[i].IsHidden && $scope.remoteControl)
$scope.remoteControl.ShowCommandBar = true;
}
}
// Logged in, page ng code...
$scope.applyHtmlEntityLayout = function(response) {
if (T3_DEBUG)
console.log('applyHtmlEntityLayout');
if (response && response.EntityUserCanView != undefined && response.EntityUserCanView == false)
{
$scope.t3_ng_svc_go.go('unauthorized.html');
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout = null;
}
if (!response ||
!response.HtmlFieldLayouts ||
!response.HtmlDetailFieldLayouts ||
!response.HtmlTableResultFieldLayouts ||
!response.HtmlSearchFieldLayouts ||
!response.HtmlCommandLayouts)
{
$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_get_html_entity_layout_error, response);
return false;
}
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout = response;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout = response.HtmlFieldLayouts;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_detailfield_layout = response.HtmlDetailFieldLayouts;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout = response.HtmlTableResultFieldLayouts;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_searchfield_layout = response.HtmlSearchFieldLayouts;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_command_layout = response.HtmlCommandLayouts;
$scope.isSearchBoxExtended = $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout.EnableExtendedSearch;
$scope.updateRemoteControl_ShowCommandBar($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_command_layout);
if (!$scope.showEditBox && $scope.search &&
(!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults ||
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.length <= 0))
{
$scope.search();
$scope.searching = false;
}
$window.document.title = $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout.EntitiesLabel;
$scope.layoutReady = true;
return true;
}
// Get entity html field from APIs
$scope.getHtmlEntityLayout = function() {
//var layout_session = sessionStorage.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout;
//var layout_local = localStorage.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout;
// Apply session layout
// if(typeof layout_session != "undefined" && layout_session !== '[object Object]')
// {
// layout_session = decodeJsonReferences(JSON.parse(layout_session));
// if ($scope.applyHtmlEntityLayout(layout_session))
// return;
// }
// DON'T Apply temporary layouts prefer a fresh copy from the server
// Apply temporary cache layout until server response with a fresh
//if(typeof layout_local != "undefined" && layout_local !== '[object Object]')
//{
// layout_local = decodeJsonReferences(JSON.parse(layout_local));
// $scope.applyHtmlEntityLayout(layout_local);
//}
$method = 'GET';
$url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_html_entity_layout_url;
$scope.modelChangeInProgress = true;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: null
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
{
//sessionStorage.setItem(
// 't3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout',
// JSON.stringify(data));
//localStorage.setItem(
// 't3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout',
// JSON.stringify(data));
$scope.applyHtmlEntityLayout(decodeJsonReferences(data));
$scope.modelChangeInProgress = false;
}
else
$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_get_html_entity_layout_error, response, status);
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status > 0)
$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_get_html_entity_layout_error, response, status);
});
};
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout = null;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout = null;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_detailfield_layout = null;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout = null;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_searchfield_layout = null;
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_command_layout = null;
// Fire get field html layout
$scope.getHtmlEntityLayout();
$scope.getToolbarCss = function()
{
if (T3_TEST || $scope.htmlEntityGrants && $scope.htmlEntityGrants.IsGod && $scope.showEditBox
&& $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData
&& $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.EntityReadOnly)
return "md-warn";
}
$scope.getToolbarDetailTitle = function()
{
var title = '';
//t3_warehousemove_html_entity_layout
if (!$scope.layoutReady)
{
return T3_NG_PAGE_LOADING;
}
if ($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout &&
$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout.EntityLabel)
title = $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout.EntityLabel;
if ($scope.htmlEntityGrants && $scope.htmlEntityGrants.IsGod && $scope.showEditBox
&& $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData
&& $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.EntityReadOnly)
title += ' (' + T3_NG_ENTITY_entity_readonly + ')';
if (T3_TEST)
title += ' (This is a TEST area) ';
return title;
}
$scope.showTitle = true;
$scope.isReadOnly = function(layoutMaster, entityMaster, layoutDeatil, entityDetail, locationInfoString)
{
if (locationInfoString = 'addbutton' && layoutMaster && layoutMaster.ReadOnlyEntity)
return true;
if ($scope.htmlEntityGrants && $scope.htmlEntityGrants.IsGod)
return false;
if (layoutMaster && layoutMaster.ReadOnlyEntity)
return true;
if (entityMaster && entityMaster.EntityReadOnly)
return true;
if (layoutDeatil && layoutDeatil.ReadOnlyEntity)
return true;
if (entityDetail && entityDetail.EntityReadOnly)
return true;
return false;
}
// Get new entity from APIs
// - t3_twig_js_rel_link_key1_costraint, use this format: "t3_ng_account_rel_link_costraint, other..."
// - t3_twig_js_rel_link_key2_costraint, use this format:
// $scope.AccountProfile.AccountId = t3_ng_account_rel_link_costraint != null ? t3_ng_account_rel_link_costraint.Id : null;
// [other...]
$scope.getNew\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = function(commitCallback, rollbackCallback) {
$scope.searching = true;
$method = 'GET';
$url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_new_url;
$scope.modelChangeInProgress = true;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: null
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200) {
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = decodeJsonReferences(data);
if($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.EntityTouched = true;
$scope.showSearchBox = false;
$scope.showEditBox = true;
$scope.showTopTenBox = false;
$location.path($scope.buildLinkToId($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id));
// Reload layout (from cache) due to md-autocomplete bug
$scope.getHtmlEntityLayout();
// Won't clear text on field reset
if (commitCallback && typeof commitCallback === "function")
commitCallback();
$scope.getHtmlEntityLayout();
$scope.modelChangeInProgress = false;
}
$scope.searching = false;
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (rollbackCallback && typeof rollbackCallback === "function")
rollbackCallback();
$scope.searching = false;
if (status > 0)
$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_new_error, response, status);
});
};
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = null;
//$scope.T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_page_title = T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_page_title;
//$scope.T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_entities_label = T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_entities_label;
// Relation links on the bottom sheet activated by rel_link button (top right corner, share icon)
// use this format:
// { name: 'Place', label: 'Destinazioni', icon: 'business' },
// { name: 'Job', label: 'Commesse', icon: 'business center' },
$scope.t3_ng_rel_links = [];
// Relation parent costraint code
// use this format:
// $scope.load_t3_ng_account_rel_link_costraint = function() {
// var sessionRelationLinkData = sessionStorage.t3_ng_account_rel_link_costraint;
// if(typeof sessionRelationLinkData != "undefined" && sessionRelationLinkData !== '[object Object]')
// return JSON.parse(sessionRelationLinkData);
// else
// return null;
// };
// $scope.t3_ng_account_rel_link_costraint = $scope.load_t3_ng_account_rel_link_costraint();
// Show relation links
$scope.showListBottomSheet = function($event) {
$mdBottomSheet.show({
templateUrl: 'html/relations_links.html',
controller: 't3_ng_ctr_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D',
targetEvent: $event
}).then(function(clickedItem) {
sessionStorage.setItem('t3_ng_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_rel_link_costraint', JSON.stringify(encodeJsonReferences($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData)));
$scope.t3_ng_svc_go.go(clickedItem.name);
});
};
// Relation link pressed
$scope.listItemClick = function($index) {
var clickedItem = $scope.t3_ng_rel_links[$index];
$mdBottomSheet.hide(clickedItem);
};
// Relation parent costraint remove
$scope.clearRelLinkCostraint = function() {
// Relation parent costraint remove code
// use this format:
// sessionStorage.setItem('t3_ng_account_rel_link_costraint', null);
// $scope.t3_ng_account_rel_link_costraint = null;
$scope.setNew\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch();
$scope.search();
}
// Get new entity handler
$scope.new = function() {
// new entity parameters
// use this format:
// "$scope.t3_ng_account_rel_link_costraint, other..."
$scope.getNew\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData(null, null
);
//$scope.showSearchBox = false;
//$scope.showEditBox = true;
//$scope.showTopTenBox = false;
}
// Ask user before save
$scope.saveWithConfirm = function(ev) {
// Appending dialog to document.body to cover sidenav in docs app
var confirm = $mdDialog.confirm()
.title(T3_NG_confirm_save)
.textContent(T3_NG_confirm_save_you_cannot_rollback)
.ariaLabel(T3_NG_confirm_save)
.targetEvent(ev)
.ok(T3_NG_confirm_save_yes)
.cancel(T3_NG_confirm_save_no);
$mdDialog.show(confirm).then(function() {
$scope.save();
}, function() { });
};
$scope.saveCommitOrRollback = function(ev, commitCallback, rollbackCallback) {
// Appending dialog to document.body to cover sidenav in docs app
var confirm = $mdDialog.confirm()
.title(T3_NG_confirm_save)
.textContent(T3_NG_confirm_save_commit_or_rollback)
.ariaLabel(T3_NG_confirm_save)
.targetEvent(ev)
.ok(T3_NG_confirm_save_yes)
.cancel(T3_NG_confirm_save_no);
$mdDialog.show(confirm).then(function() {
$scope.save(commitCallback, rollbackCallback);
}, function() {
if (rollbackCallback && typeof rollbackCallback === "function")
rollbackCallback();
});
};
$scope.serverErrors = [];
$scope.printLabel = function(label) {
var ws = new WebSocket("ws://localhost:9180/service");
ws.onopen = function () {
//var str = "";
//for (i = 0; i
0)
$scope.showFeedbackMessage("Problema con la stampa, ritentare.", 'warning');
//$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_search_error, response, status);
});
}
$scope.searchPrint = function(searchObject)
{
if (!searchObject)
return;
var $method = 'POST';
var $url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_searchprint_url;
searchObject.Includes = [];
var payload = encodeJsonReferences(searchObject);
var headers = T3_API_authorized_request_headers($scope.loginData.token);
if (T3_DEBUG)
console.log('searchPrint()');
$http({
method: $method,
url: $url,
headers: headers,
data: payload,
responseType: 'arraybuffer'
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
{
setTimeout(function(){
var file = new Blob([data], { type: 'application/pdf' });
var fileURL = URL.createObjectURL(file);
//window.open(fileURL, '_blank');
printJS({printable: fileURL, type: 'pdf'});
}, 100);
}
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status > 0)
$scope.showFeedbackMessage("Problema con la stampa, ritentare.", 'warning');
//$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_search_error, response, status);
});
};
//
// Printing routines END
//
// Save directly
$scope.save = function(commitCallback, rollbackCallback) {
// if (!$scope.forms.masterEditboxForm.$valid)
// {
// $scope.showFeedbackMessage(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_form_error, 'error')
// return;
// }
$scope.searching = true;
$scope.serverErrors = [];
$method = ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id > 0) ? 'PUT' : 'POST';
$url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_url;
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id > 0)
$url = $url + '/' + $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id;
$scope.modelChangeInProgress = true;
if (T3_EN_GZIP)
{
// GZIP compression
var payload = new Blob([pako.gzip(encodeJsonReferences($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData))]);
var headers = T3_API_authorized_request_headers($scope.loginData.token, null, 'gzip');
}
else
{
var payload = encodeJsonReferences($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData);
var headers = T3_API_authorized_request_headers($scope.loginData.token);
}
$http({
method: $method,
url: $url,
headers: headers,
data: payload // return a encoded copy
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.searching = false;
if (status == 200) {
if (commitCallback && typeof commitCallback === "function")
commitCallback();
else
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = decodeJsonReferences(data);
}
if (status == 201) {
//$scope.select(decodeJsonReferences(data));
if (commitCallback && typeof commitCallback === "function")
commitCallback();
else
$scope.selectByIdPrivate(decodeJsonReferences(data).Id);
$scope.showFeedbackMessage(T3_NG_data_saved);
}
if (status == 204) {
$scope.showFeedbackMessage(T3_NG_data_saved_without_entity_response);
}
$scope.modelChangeInProgress = false;
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
var isModelError = false;
var isFieldError = false;
if (status == 400 && data.ModelState != undefined)
{
var errors = [];
for(var property in data.ModelState) {
if (!property.startsWith('$'))
{
if (property == '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D')
{
$scope.showFeedbackMessage(data.ModelState[property][0], 'error');
isFieldError = true;
}
else
{
var field = $scope.forms.masterEditboxForm[property];
if (field !== undefined)
{
isFieldError = true;
errors.push({
field: property,
type: "custom",
value: null,
message: data.ModelState[property][0]
});
}
}
}
}
$scope.serverErrors = errors;
}
if (!isModelError && status > 0)
{
$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_save_error, response, status);
}
$scope.modelChangeInProgress = false;
$scope.searching = false;
if (rollbackCallback && typeof rollbackCallback === "function")
rollbackCallback();
});
};
// Upload
$scope.uploadXls = function() {
$scope.searching = true;
$method = 'POST';
$url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_upload_xml_url;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token, 'application/vnd.ms-excel'),
data: $scope.file
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.searching = false;
if (status == 201) {
$scope.select(decodeJsonReferences(data));
$scope.showFeedbackMessage(T3_NG_data_saved);
}
if (status == 204) {
$scope.showFeedbackMessage(T3_NG_data_saved_without_entity_response);
}
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.searching = false;
if (status > 0)
$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_upload_xml_error, response, status);
});
};
$scope.downloadXls = function(tableId) {
// var tab_text="";
// var textRange; var j=0;
// tab = document.getElementById(tableId); // id of table
// for(j = 0 ; j < tab.rows.length ; j++)
// {
// tab_text=tab_text+tab.rows[j].innerHTML+"
";
// //tab_text=tab_text+"";
// }
// tab_text=tab_text+"
";
// tab_text= tab_text.replace(/]*>|<\/A>/g, "");//remove if u want links in your table
// tab_text= tab_text.replace(/
]*>/gi,""); // remove if u want images in your table
// tab_text= tab_text.replace(/]*>|<\/input>/gi, ""); // reomves input params
// var ua = window.navigator.userAgent;
// var msie = ua.indexOf("MSIE ");
// if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
// {
// txtArea1.document.open("txt/html","replace");
// txtArea1.document.write(tab_text);
// txtArea1.document.close();
// txtArea1.focus();
// sa=txtArea1.document.execCommand("SaveAs",true,tableId+".xls");
// }
// else //other browser not tested on IE 11
// sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
// return (sa);
var data = new Blob([document.getElementById(tableId).innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(data, "\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.xls");
}
// Ask user before delete
$scope.multiDeleteWithConfirm = function(ev, entity) {
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults)
return;
var tmr = null;
var toDelete = [];
for(var i = 0; i < $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.length; i++)
{
var obj = $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults[i];
if (obj.EntityChecked)
toDelete.push(obj);
}
if (toDelete.length <= 0)
return;
// Appending dialog to document.body to cover sidenav in docs app
var confirm = $mdDialog.confirm()
.title(T3_NG_confirm_delete)
.textContent(T3_NG_confirm_delete_you_cannot_rollback)
.ariaLabel(T3_NG_confirm_delete)
.targetEvent(ev)
.ok(T3_NG_confirm_delete_yes)
.cancel(T3_NG_confirm_delete_no);
$mdDialog.show(confirm).then(function() {
for(var i = 0; i < toDelete.length; i++)
{
$scope.delete(toDelete[i], function() {
if (tmr)
clearTimeout(tmr);
tmr = setTimeout(function() {
$scope.showFeedbackMessage(T3_NG_data_deleted);
}, 1500);
});
}
}, function(entity) { });
$scope.EntityCheckedAll = false;
};
// Ask user before delete
$scope.deleteWithConfirm = function(ev, entity) {
// Appending dialog to document.body to cover sidenav in docs app
var confirm = $mdDialog.confirm()
.title(T3_NG_confirm_delete)
.textContent(T3_NG_confirm_delete_you_cannot_rollback)
.ariaLabel(T3_NG_confirm_delete)
.targetEvent(ev)
.ok(T3_NG_confirm_delete_yes)
.cancel(T3_NG_confirm_delete_no);
if (entity)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = entity;
$mdDialog.show(confirm).then(function() {
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData)
$scope.delete($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData);
}, function(entity) { });
};
// Delete directly
$scope.delete = function(entity, commitCallback) {
$scope.searching = true;
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = entity;
$method = 'DELETE';
$url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_url;
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id > 0)
$url = $url + '/' + $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id;
$scope.modelChangeInProgress = true;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: null, //encodeJsonReferences($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData)
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.searching = false;
$scope.switchOnSearchMode(true);
$scope.search();
if (commitCallback && typeof commitCallback === "function")
commitCallback();
else
$scope.showFeedbackMessage("Dati cancellati");
$scope.modelChangeInProgress = false;
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.searching = false;
$scope.modelChangeInProgress = false;
if (status >= 500)
$scope.showFeedbackMessage(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_delete_error, "warning");
else
$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_delete_error, response, status);
});
};
$scope.setNew\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch = function (commitCallback)
{
console.log('setNew\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch');
$method = 'GET';
$url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_newsearchobject_url;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: encodeJsonReferences($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch)
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
{
//$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults = []; // Clear results
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch = decodeJsonReferences(data);
if (commitCallback && typeof commitCallback === "function")
commitCallback($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch);
}
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status > 0)
$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_newsearchobject_error, response, status);
});
};
$scope.getCached\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch = function() {
var searchObject = localStorage.t3_\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch;
if (searchObject)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch = decodeJsonReferences(JSON.parse(searchObject));
else
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch = undefined;
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch)
{
$scope.setNew\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch(function () {
if (!$scope.searching && $scope.showSearchBox)
$scope.search();
});
}
}
$scope.getCached\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch();
$scope.isDisabled = false;
$scope.noCache = true;
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults = undefined;
$scope.searching = false;
$scope.showSearchBox = false;
// This causes a bug that hides extendedseachbox button when refreshing page
//$scope.isSearchBoxExtended = false;
$scope.showSearchBoxExtended = false;
$scope.showTopTenBox = true;
$scope.showEditBox = false;
$scope.modelChangeInProgress = false;
// Show/hide searchbox
$scope.switchOnSearchMode = function(show) {
if (show === undefined)
show = !$scope.showSearchBox
$scope.showSearchBox = show;
$scope.showTopTenBox = show;
$scope.showEditBox = !show;
if (show == false)
$scope.searching = false;
}
// Show/hide showSearchBoxExtended
$scope.toggleShowSearchBoxExtended = function() {
$scope.showSearchBoxExtended = !$scope.showSearchBoxExtended;
}
$scope.showSearchBoxBar = true;
$scope.openSearchBoxExtended = function() {
$scope.switchOnSearchMode(true);
var useFullScreen = ($mdMedia('sm') || $mdMedia('xs'));
$mdDialog.show({
controller: FormDialog_DialogController,
templateUrl: 'html/common/searchdialog.html',
parent: angular.element(document.body),
targetEvent: undefined,
clickOutsideToClose:true,
fullscreen: useFullScreen,
locals: {
title: T3_NG_search_fields,
entity: $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch,
layout: $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_searchfield_layout,
loginData: $scope.loginData
}
})
.then(function(newSearchObject) {
$scope.search();
}, function() {
});
$scope.$watch(function() {
return $mdMedia('xs') || $mdMedia('sm');
}, function(wantsFullScreen) {
$scope.customFullscreen = (wantsFullScreen === true);
});
};
$scope.orderByParseDirective = function(fieldName, directive)
{
switch(directive)
{
case 'format-autocomplete':
{
fieldName += '.Name';
break;
}
case 'format-select':
{
fieldName += '.Name';
break;
}
case 'format-input':
{
fieldName = fieldName;
break;
}
case 'format-datetime':
{
fieldName = fieldName;
break;
}
case 'format-date':
{
fieldName = fieldName;
break;
}
case 'format-time':
{
fieldName = fieldName;
break;
}
case 'format-duration':
{
fieldName += 'Ticks';
break;
}
default:
{
fieldName = fieldName;
}
}
return fieldName;
}
$scope.orderByIsAscending = function(fieldName, directive)
{
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch)
return false;
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy)
{
return false;
}
fieldName = $scope.orderByParseDirective(fieldName, directive);
return ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.FieldName == fieldName && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.Direction == 0);
}
$scope.orderByIsDescending = function(fieldName, directive)
{
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch)
return false;
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy)
{
return false;
}
fieldName = $scope.orderByParseDirective(fieldName, directive);
return ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.FieldName == fieldName && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.Direction == 1);
}
$scope.orderBySet = function(fieldName, directive) {
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch)
return;
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy)
{
return;
}
fieldName = $scope.orderByParseDirective(fieldName, directive);
if (!fieldName)
{
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.FieldName = null;
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.Direction = 0;
}
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.FieldName == fieldName)
{
// Invert direction
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.Direction == 0)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.Direction = 1;
else
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.Direction = 0;
}
else
{
// Set new order by
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.FieldName = fieldName;
// Reset direction
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.OrderBy.Direction = 0;
}
$scope.search();
}
$scope.searchNext = function() {
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging)
{
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page < 1)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page = 1;
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page = parseInt($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page) + 1;
$scope.search();
}
}
$scope.searchBefore = function() {
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging)
{
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page = $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page - 1;
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page < 1)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page = 1;
$scope.search();
}
}
$scope.searchCanceler = undefined;
$scope.delayedSearchTimeout = null;
$scope.delayedSearch = function(pattern) {
if (pattern.length <= 2)
return;
var searchDelay = 1000;
if ($scope.delayedSearchTimeout != null)
clearTimeout($scope.delayedSearchTimeout);
$scope.delayedSearchTimeout = setTimeout(function() {
$scope.search();
}, searchDelay);
}
$scope.pageIncludes = [];
$scope.useFastSearch = false;
$scope.useFastSearchDoNotPerformAnyCalculation = false;
$scope.prepareFastSearchFields = function() {
if (!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch && T3_DEBUG)
{
alert('$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch not ready!');
return;
}
if (!$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout && T3_DEBUG)
{
alert('$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout not ready!');
return;
}
if (!$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout && T3_DEBUG)
{
alert('$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout not ready!');
return;
}
// Init
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.FastSearch = $scope.useFastSearch;
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.FastSearchDoNotPerformAnyCalculation = $scope.useFastSearchDoNotPerformAnyCalculation;
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.FastSearchFields = [];
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Includes = [];
// Add page includes
//for (var i = 0; i < $scope.pageIncludes.length; i++)
//{
// $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Includes.push($scope.pageIncludes[i]);
//}
// Add FastSearchFields
for (i = 0; i < $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout.length; i++)
{
if (!$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout[i].IsHidden)
{
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.FastSearchFields.push($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout[i].FieldName);
}
}
// Add lookup fields
for (i = 0; i < $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout.length; i++)
{
if ($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].NgDirectives == 'format-autocompletechips' //||
//$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].NgDirectives == 'format-autocomplete' ||
//$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].NgDirectives == 'format-select'
)
{
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Includes &&
!$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Includes.includes($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].FieldName))
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Includes.push($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].FieldName);
}
}
}
// Perform search
$scope.search = function(callback, errorCallback) {
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch === undefined || $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch == null)
return;
var $method = 'POST';
var $url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_search_url;
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Includes = []; // clear includes request
//$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults = []; // Clear results
if ($scope.searchCanceler)
$scope.searchCanceler.resolve();
$scope.searchCanceler = $q.defer();
$scope.searching = true;
$scope.modelChangeInProgress = true;
$location.path($scope.buildLinkToId());
$scope.prepareFastSearchFields();
localStorage.setItem('t3_\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch', JSON.stringify(encodeJsonReferences($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch)));
$scope.switchOnSearchMode(true);
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.RequestTimestamp = moment();
if (T3_EN_GZIP)
{
// GZIP compression
var payload = new Blob([pako.gzip(encodeJsonReferences($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch))]);
var headers = T3_API_authorized_request_headers($scope.loginData.token, null, 'gzip');
}
else
{
var payload = encodeJsonReferences($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch);
var headers = T3_API_authorized_request_headers($scope.loginData.token);
}
if (T3_DEBUG)
console.log('search()');
$scope.refresh2LastUpdateAt = null;
$http({
method: $method,
url: $url,
headers: headers,
data: payload,
timeout: $scope.searchCanceler.promise
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.searching = false;
if (status == 200)
{
$scope.refresh2LastUpdateAt = Date.now();
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults = decodeJsonReferences(data);
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = null;
$scope.modelChangeInProgress = false;
if (callback && typeof callback === "function")
callback($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults);
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.length <= 0 && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page > 1)
{
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page--;
//if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page < 1)
// $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page = 1;
setTimeout(function() { $scope.search(); }, 10);
}
}
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.searching = false;
$scope.modelChangeInProgress = false;
if (errorCallback && typeof errorCallback === "function")
errorCallback(response);
else if (status > 0)
$scope.showFeedbackMessage("Problema con la ricerca, ritentare.", 'warning');
//$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_search_error, response, status);
});
};
$scope.prepareFastSearchFields2 = function(searchPayload) {
if (!searchPayload && T3_DEBUG)
{
return;
}
if (!$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout && T3_DEBUG)
{
return;
}
if (!$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout && T3_DEBUG)
{
return;
}
// Init
searchPayload.FastSearch = $scope.useFastSearch;
searchPayload.FastSearchDoNotPerformAnyCalculation = $scope.useFastSearchDoNotPerformAnyCalculation;
searchPayload.FastSearchFields = [];
searchPayload.Includes = [];
// Add page includes
//for (var i = 0; i < $scope.pageIncludes.length; i++)
//{
// searchPayload.Includes.push($scope.pageIncludes[i]);
//}
// Add FastSearchFields
for (i = 0; i < $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout.length; i++)
{
if (!$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout[i].IsHidden)
{
searchPayload.FastSearchFields.push($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_tableresultfield_layout[i].FieldName);
}
}
// Add lookup fields
for (i = 0; i < $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout.length; i++)
{
if ($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].NgDirectives == 'format-autocompletechips' //||
//$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].NgDirectives == 'format-autocomplete' ||
//$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].NgDirectives == 'format-select'
)
{
if (searchPayload && searchPayload.Includes &&
!searchPayload.Includes.includes($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].FieldName))
searchPayload.Includes.push($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].FieldName);
}
}
}
// Reload page every 2 hours
$scope.pageRefreshTimerDuration = 7200000;
$scope.pageRefreshTimer = setTimeout(function(){
//alert('La pagina è aperta da troppo tempo, verrà ricaricata!');
window.location.reload(true); // true param means hard reload
}, $scope.pageRefreshTimerDuration);
// Perform search2
$scope.search2 = function(searchPayload, okCallback, errorCallback) {
if (searchPayload === undefined || searchPayload == null)
return;
var $method = 'POST';
var $url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_search_url;
//if (!searchPayload.RequestTimestamp)
searchPayload.RequestTimestamp = moment();
var payload = encodeJsonReferences(searchPayload);
var headers = T3_API_authorized_request_headers($scope.loginData.token);
if (T3_DEBUG)
console.log('search2()');
$http({
method: $method,
url: $url,
headers: headers,
data: payload
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
data = decodeJsonReferences(data);
if (okCallback && typeof okCallback === "function")
okCallback(data, status, statusText, headers, config);
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (errorCallback && typeof errorCallback === "function")
errorCallback(data, status, statusText, headers, config);
});
};
$scope.refresh2Results = [];
$scope.refresh2ResultsPerPage = 20;
$scope.refresh2LastMousePosition = null;
$scope.refresh2LastUpdateAt = Date.now();
$scope.refresh2CurrentMousePosition = null;
$scope.refreshTimer2 = null;
$scope.refreshTimerDuration2 = 10000;
$scope.refreshTimerDuration2Anycase = 30000;
$scope.refreshTimerRunning2 = false;
$scope.onMouseMove = function(event)
{
$scope.refresh2CurrentMousePosition = event.clientX + '-' + event.clientY;
}
$scope.userIsActive = function() {
var userIsActive = ($scope.refresh2LastMousePosition != $scope.refresh2CurrentMousePosition);
if (userIsActive)
{
$scope.refresh2LastMousePosition = $scope.refresh2CurrentMousePosition;
return true;
}
return false;
}
$scope.refresh2 = function(running) {
if (running === undefined)
$scope.refreshTimerRunning2 = !$scope.refreshTimerRunning2;
else
$scope.refreshTimerRunning2 = running;
if (!$scope.refreshTimerRunning2)
{
return;
}
$scope.refreshTimer2 = $timeout(function () {
if (!$scope.refreshTimerRunning2)
return;
if ($scope.showEditBox)
return;
var searchPayload = $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch;
if (!searchPayload || !searchPayload.Paging || !searchPayload.Paging.Page)
return;
if (!$scope.userIsActive() || (Date.now() - $scope.refresh2LastUpdateAt) > $scope.refreshTimerDuration2Anycase)
{
if (T3_DEBUG)
{
if ((Date.now() - $scope.refresh2LastUpdateAt) > $scope.refreshTimerDuration2Anycase)
{
console.log('refreshTimerDuration2Anycase');
}
else
{
console.log('refreshTimerDuration2');
}
}
searchPayload.Paging.ResultsPerPage = $scope.refresh2ResultsPerPage;
// if (!$scope.refresh2Results || $scope.refresh2Results.length <= 0)
// searchPayload.Paging.Page = 1;
$scope.searching = true;
$scope.search2(searchPayload,
// ok
function(data, status, statusText, headers, config) {
$scope.refresh2LastUpdateAt = Date.now();
$scope.searching = false;
if (data.length <= 0)
{
searchPayload.Paging.Page = 1;
$scope.searching = true;
$scope.search2(searchPayload,
// ok
function(data, status, statusText, headers, config) {
$scope.searching = false;
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults = data;
},
// error
function(data, status, statusText, headers, config) {
$scope.searching = false;
$scope.showFeedbackMessage("Problemi di connessione...", 'warning');
}
);
}
else
{
if (!$scope.refresh2StillOnPage1)
searchPayload.Paging.Page++;
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults = data;
}
},
// error
function(data, status, statusText, headers, config) {
$scope.searching = false;
$scope.showFeedbackMessage("Problemi di connessione...", 'warning');
}
);
}
$scope.refresh2(true);
}, $scope.refreshTimerDuration2);
}
$scope.refresh = function(running) {
if (running === undefined)
$scope.refreshTimerRunning = !$scope.refreshTimerRunning;
else
$scope.refreshTimerRunning = running;
if (!$scope.refreshTimerRunning)
return;
$scope.refreshTimer = $timeout(function () {
if ($scope.refreshTimerRunning)
{
if ($scope.showEditBox && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData)
$scope.select($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData);
if (!$scope.showEditBox)
{
if ($scope.refreshTimerRunning &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.length <= 0)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page = 1;
if ($scope.refreshTimerRunning &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page++;
$scope.search(function() {
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults.length <= 0)
{
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearch.Paging.Page = 1;
$scope.search(function() {}, function() {
$scope.showFeedbackMessage("Problemi di connessione...", 'warning');
});
}
}, function() {
$scope.showFeedbackMessage("Problemi di connessione...", 'warning');
});
}
$scope.refresh(true);
}
else
$scope.refresh(false);
}, $scope.refreshTimerDuration);
}
$scope.refreshTimer = null;
$scope.refreshTimerDuration = 10000;
$scope.refreshTimerRunning = false;
$scope.prepareSelectPaylod = function()
{
var selectPayload = {
SelectTop: 1,
Id: null,
Includes: []
}
// Add lookup fields includes
if (!$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout && T3_DEBUG)
{
alert('$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout is missing');
return selectPayload;
}
// Add page includes
for (var i = 0; i < $scope.pageIncludes.length; i++)
{
selectPayload.Includes.push($scope.pageIncludes[i]);
}
// Add lookup fields includes
for (i = 0; i < $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout.length; i++)
{
if ($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].NgDirectives == 'format-autocompletechips' //||
//$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].NgDirectives == 'format-autocomplete' ||
//$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].NgDirectives == 'format-select'
)
{
if (!selectPayload.Includes.includes($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].FieldName))
selectPayload.Includes.push($scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout[i].FieldName);
}
}
return selectPayload;
}
$scope.selectByIdPrivate = function(id, commitCallback, rollbackCallback) {
var selectPayload = $scope.prepareSelectPaylod();
selectPayload.Id = id;
if (!$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout)
{
console.log('selectByIdPrivate id = ' + id);
$scope.showFeedbackMessage('Unable to proceed without a loaded layout, please try to reload page!', 'warning');
return;
}
if (!commitCallback)
$scope.searching = true;
$method = 'POST';
$url = T3_API_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_search_url;
//$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DSearchResults = []; // Clear results
$scope.modelChangeInProgress = true;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: encodeJsonReferences(selectPayload)
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (!commitCallback)
$scope.searching = false;
if (data.length <= 0)
{
if (rollbackCallback && typeof rollbackCallback === "function")
rollbackCallback();
return;
}
if (status == 200)
{
// if "commitCallback" is null go to PAGE /id
var entity = decodeJsonReferences(data)[0];
if (!commitCallback)
{
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = entity;
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.EntityTouched = true;
// If user comes back to this page it shows the current entity
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id)
localStorage.setItem('t3_' + '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D'.toLowerCase() + '_go_to_id', $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id);
if (id > 0)
$location.path($scope.buildLinkToId(id));
// Switch to edit mode only if callback is null
$scope.showSearchBox = false;
$scope.showEditBox = true;
$scope.showTopTenBox = false;
}
else
{
if (commitCallback && typeof commitCallback === "function")
commitCallback(entity);
}
}
$scope.modelChangeInProgress = false;
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (!commitCallback)
$scope.searching = false;
$scope.modelChangeInProgress = false;
if (rollbackCallback && typeof rollbackCallback === "function")
rollbackCallback();
if (status > 0)
$scope.exception(T3_NG_\x7B\x5B\x7B\x20BUILDLINKTOOTHERENTITYID\x28ATTACHMENT_ATTACHMENTENTITYNAME,\x20ATTACHMENT_ATTACHMENTENTITYID\x29\x20\x7D\x5D\x7D_select_error, response, status);
});
};
// Make item the current entity, then show edit box
$scope.selectById = function(id, commitCallback, rollbackCallback) {
if (!id)
return;
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id == id)
return;
if (!$scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout)
{
// Wait for layout load for at least 2 seconds, then raise error because
// if the selection is made with a null collection on save the collection
// will be cleared with data loss.
setTimeout(function() {
$scope.selectByIdPrivate(id, function(entity)
{
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = entity;
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.EntityTouched = true;
// If user comes back to this page it shows the current entity
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id)
localStorage.setItem('t3_' + '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D'.toLowerCase() + '_go_to_id', $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id);
if (id > 0)
$location.path($scope.buildLinkToId(id));
// Switch to edit mode only if callback is null
$scope.showSearchBox = false;
$scope.showEditBox = true;
$scope.showTopTenBox = false;
if (commitCallback && typeof commitCallback === "function")
commitCallback(entity);
}, rollbackCallback);
}, 2000)
} else {
$scope.selectByIdPrivate(id, function(entity)
{
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = entity;
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData)
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.EntityTouched = true;
// If user comes back to this page it shows the current entity
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData && $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id)
localStorage.setItem('t3_' + '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D'.toLowerCase() + '_go_to_id', $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id);
if (id > 0)
$location.path($scope.buildLinkToId(id));
// Switch to edit mode only if callback is null
$scope.showSearchBox = false;
$scope.showEditBox = true;
$scope.showTopTenBox = false;
if (commitCallback && typeof commitCallback === "function")
commitCallback(entity);
}, rollbackCallback);
}
};
$scope.select = function(item) {
if (!item)
return;
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id == item.Id &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.EntityTouched)
{
// Refresh saved entity
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData = null;
$scope.showEditBox = false;
}
var id = null;
if ($scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData)
id = $scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.Id;
var memGetIdFromEntity = false;
if ($scope.getIdFromEntity && typeof $scope.getIdFromEntity === "function")
{
id = $scope.getIdFromEntity(item);
memGetIdFromEntity = true;
}
else if (item && item.Id)
id = item.Id;
// getIdFromEntity has handled request, suppress warning message
if (memGetIdFromEntity && id == null)
return;
if (!id || id == 0)
{
$scope.showFeedbackMessage(T3_NG_ENTITY_select_unaviable_warning, 'warning');
return;
}
$scope.searching = true;
$scope.selectById(item.Id, function() {
// Commit id found
$scope.switchOnSearchMode(false);
$scope.searching = false;
}, function() {
// Rollback id not found
$scope.switchOnSearchMode(true);
$scope.searching = false;
});
};
var checkValues = [false, true, null];
var len = checkValues.length;
var index = 0;
$scope.checkBoxIsChecked = function(entity, fieldName) {
if (!entity || !fieldName)
return false;
return (entity[fieldName] == true);
}
$scope.checkBoxIsIndeterminated = function(entity, fieldName) {
if (!entity || !fieldName)
return true;
return (entity[fieldName] == null);
}
$scope.checkBoxModelChange = function(entity, fieldName) {
}
$scope.transformChip = function(chip) {
// If it is an object, it's already a known chip
if (angular.isObject(chip)) {
return chip;
}
}
//$scope.switchOnSearchMode(true);
$scope.evalShowReverseRow = function(fieldName, targetValue) {
if (fieldName && !fieldName.startsWith("Reverse"))
return true;
else
if (fieldName &&
fieldName.startsWith("Reverse") &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.DocumentProfile &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.DocumentProfile.Reason &&
$scope.\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7DData.DocumentProfile.Reason.HasReverseRow)
return true;
else
return false;
};
// relationsbox.js.twig
// ONE 2 ONE/MANY relations
// 1
// resultsbox_card.js.twig
$scope.FeedbackMessage = '';
$scope.isFeedbackMessage = false;
$scope.clearFeedbackMessage = function() {
$scope.FeedbackMessage = '';
$scope.isFeedbackMessage = false;
}
$scope.showFeedbackMessage = function(msg, type) {
if (!type)
{
$scope.showSuccessToast(msg);
return;
}
switch(type) {
case 'error':
$scope.showErrorToast(msg);
break;
case 'warning':
$scope.showWarningToast(msg);
break;
default:
$scope.showSuccessToast(msg);
}
// $scope.showSuccessToast(msg);
// $scope.FeedbackMessage = msg;
// $scope.isFeedbackMessage = true;
// setTimeout($scope.clearFeedbackMessage, 3000);
}
$scope.clearFeedbackMessage();
// // Sidenav code
$scope.t3EnableAttachments = T3_EN_ATTACHMENTS;
function debounce(func, wait, context) {
var timer;
return function debounced() {
var context = $scope,
args = Array.prototype.slice.call(arguments);
$timeout.cancel(timer);
timer = $timeout(function() {
timer = undefined;
func.apply(context, args);
}, wait || 10);
};
}
function buildDelayedToggler(navID) {
return debounce(function() {
// Component lookup should always be available since we are not using `ng-if`
$mdSidenav(navID)
.open()
.then(function () {
$scope.$broadcast('onSidenavShow');
})
.catch(function(error) {
console.log(error);
// handle errors
});;
}, 200);
}
$scope.toggleRelSidenav = buildDelayedToggler('attachmentsidenav');
$scope.openRelSidenav2 = function(entity, entityId, entityLayout) {
$scope.AttachmentsRelatedToEntity = entity;
if (!entityId)
entityId = $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout.EntityName;
$scope.AttachmentsRelatedToEntityId = entityId;
if (!entityLayout)
entityLayout = $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_field_layout;
$scope.AttachmentsRelatedToEntityLayout = entityLayout;
$scope.AttachmentsRelatedToList = [ {
EntityId: entityId,
Id: entity ? entity.Id : null,
label1: $scope.t3_\x7B\x5B\x7B\x20buildlinktootherentityid\x28attachment_attachmententityname,\x20attachment_attachmententityid\x29\x20\x7D\x5D\x7D_html_entity_layout.EntityLabel,
label2: entity ? ((entity.Name && entity.Name != '') ? entity.Name : 'Oggetto corrente') : 'Alla pagina corrente' ,
default: true
} ];
for (var i = 0; i < entityLayout.length; i++)
{
var field = entityLayout[i];
if (!field) // show also attachments of hidden fields || field.IsHidden)
continue;
if (field.IsHidden)
continue;
if (!(field.NgDirectives == 'format-autocomplete' || field.NgDirectives == 'format-autocompletechips'))
continue;
var obj = null;
if (entity)
obj = entity[field.FieldName];
if (!obj || typeof obj !== 'object' || (obj instanceof Date) || moment.isMoment(obj) || (obj && moment.isDuration(obj))) // is null or primitive value
continue;
if (Array.isArray(obj) && obj.length <= 0)
continue;
// if is an array
if (obj.length && obj.length > 0)
{
for(var j = 0; j < obj.length; j++)
{
$scope.AttachmentsRelatedToList.push({
EntityId: obj[j].EntityId,
Id: obj[j].Id,
label1: entityLayout[i].FieldLabel,
label2: obj[j].Name,
default: false
});
}
}
else
{
$scope.AttachmentsRelatedToList.push({
EntityId: obj.EntityId,
Id: obj.Id,
label1: entityLayout[i].FieldLabel,
label2: obj.Name,
default: false
});
}
}
$scope.toggleRelSidenav();
}
$scope.openRelSidenav = function(entity, entityId, entityLayout) { $scope.openRelSidenav2(entity, entityId, entityLayout); }
// // [end] Sidenav code
// -1
}
});
t3_ng_app_index.controller('t3_ng_ctr_attachments', function ($scope, $timeout, $mdSidenav, $log, $http, $mdToast, $mdDialog, $window) {
$scope.showUploadFrame = false;
$scope.toggleUploadFrame = function()
{
$scope.showUploadFrame = !$scope.showUploadFrame;
}
$scope.$on('onSidenavShow', function(e) {
$scope.refreshAttachments();
});
$scope.entityRelatedAttachments = [];
$scope.linkedEntityRelatedAttachments = [];
$scope.classRelatedAttachments = [];
$scope.newAttachment = { LinkTo: null };
$scope.resetForm = function()
{
var form = document.getElementById('newAttachmentsForm');
form.reset();
$scope.newAttachment = {};
$scope.showUploadFrame = false;
}
$scope.openAttachmentForm = function(attachment)
{
var form = document.getElementById('newAttachmentsForm');
form.reset();
$scope.newAttachment = {};
$scope.showUploadFrame = false;
setTimeout(function() {
var found = null;
if (attachment)
{
$scope.newAttachment.Id = attachment.Id;
$scope.newAttachment.Title = attachment.Title;
$scope.newAttachment.Description = attachment.Description;
var list = $scope.AttachmentsRelatedToList;
for(var i = 0; i < list.length; i++)
{
if (list[i].EntityId == attachment.AttachmentEntityName &&
list[i].Id == attachment.AttachmentEntityId)
{
found = list[i];
break;
}
}
if (!found)
{
found = {
EntityId: attachment.AttachmentEntityName,
Id: attachment.AttachmentEntityId,
};
list.push(found);
}
}
else
{
var list = $scope.AttachmentsRelatedToList;
for(var i = 0; i < list.length; i++)
{
if (list[i].default)
{
found = list[i];
break;
}
}
}
$scope.newAttachment.LinkTo = found;
$scope.showUploadFrame = true;
}, 100);
}
$scope.uploadAttachments = function()
{
var form = document.getElementById('newAttachmentsForm');
var formFiles = document.getElementById('newAttachmentsFormFiles');
//if (!formFiles || formFiles.files.length <= 0)
// return;
var formData = new FormData(form);
$scope.searching = true;
$scope.serverErrors = [];
$method = 'POST';
$url = T3_API_ATTACHMENT_upload_url;
// https://stackoverflow.com/questions/35722093/send-multipart-form-data-files-with-angular-using-http
var headers = T3_API_authorized_request_headers($scope.loginData.token)
headers['Content-Type'] = undefined;
$http({
method: $method,
url: $url,
headers: headers,
data: formData
}).then(function onSuccess(response) {
$scope.searching = false;
$scope.showFeedbackMessage(T3_NG_attachements_uploaded);
$scope.resetForm();
$scope.refreshAttachments();
}).catch(function onError(response) {
$scope.searching = false;
$scope.$parent.showFeedbackMessage(T3_NG_attachements_upload_error, 'error');
});
}
$scope.AttachmentSearch = null;
$scope.searchAttachments = function(attachmentSearch, callback) {
if (!attachmentSearch)
return;
$method = 'POST';
$url = T3_API_ATTACHMENT_search_url;
//if ($scope.searchCanceler)
// $scope.searchCanceler.resolve();
//$scope.searchCanceler = $q.defer();
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: encodeJsonReferences(attachmentSearch),
//timeout: $scope.searchCanceler.promise
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status == 200)
if (callback && typeof callback === "function")
callback(decodeJsonReferences(data));
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status > 0)
$scope.$parent.showFeedbackMessage(T3_NG_TEXT_ATTACHMENT_search_error, 'error');
});
};
$scope.searchEntityRelatedAttachments = function(entity, callback)
{
if (!entity)
return;
var attachmentSearch =
{
AttachmentEntityName: entity.EntityId,
AttachmentEntityId: entity.Id
};
if (callback && typeof callback === "function")
$scope.searchAttachments(attachmentSearch, function(results) {
if (results && entity)
entity.HasAttachments = (results.length > 0);;
callback(entity, results);
});
else
$scope.searchAttachments(attachmentSearch, function(results) {
for(var k = 0; k < results.length; k++)
results[k].LinkedToEntityName = entity.Name;
if (results && entity)
entity.HasAttachments = (results.length > 0);
$scope.entityRelatedAttachments = results;
});
}
$scope.searchLinkedEntityRelatedAttachments = function(entity, htmlFieldLayout)
{
$scope.linkedEntityRelatedAttachments = [];
if (!entity || !htmlFieldLayout)
return;
for(var i = 0; i < htmlFieldLayout.length; i++)
{
var field = htmlFieldLayout[i];
if (!field) // show also attachments of hidden fields || field.IsHidden)
continue;
if (!(field.NgDirectives == 'format-autocomplete' || field.NgDirectives == 'format-autocompletechips'))
continue;
var obj = entity[field.FieldName];
if (!obj || typeof obj !== 'object' || (obj instanceof Date) || moment.isMoment(obj) || (obj && moment.isDuration(obj))) // is null or primitive value
continue;
if (Array.isArray(obj) && obj.length <= 0)
continue;
// if is an array
if (obj.length && obj.length > 0)
{
for(var j = 0; j < obj.length; j++)
{
$scope.searchEntityRelatedAttachments(obj[j], function(entity, results) {
for(var k = 0; k < results.length; k++)
results[k].LinkedToEntityName = entity.Name;
$scope.linkedEntityRelatedAttachments = $scope.linkedEntityRelatedAttachments.concat(results);
});
}
}
else
{
$scope.searchEntityRelatedAttachments(obj, function(entity, results) {
for(var k = 0; k < results.length; k++)
results[k].LinkedToEntityName = entity.Name;
$scope.linkedEntityRelatedAttachments = $scope.linkedEntityRelatedAttachments.concat(results);
});
}
}
}
$scope.searchClassRelatedAttachments = function(entityName)
{
var attachmentSearch =
{
AttachmentEntityName: entityName,
AttachmentEntityId: null,
UnrelatedToSpecificEntity: true
};
$scope.searchAttachments(attachmentSearch, function(results) {
$scope.classRelatedAttachments = results;
});
}
/**
$scope.getAttachmentEntityName = function(choice)
{
var entityName = null;
if (choice)
entityName = choice.entityId;
// old...
if (!entityName && $scope.$parent.AttachmentsRelatedToEntity)
entityName = $scope.$parent.AttachmentsRelatedToEntity.EntityId;
if (!entityName && $scope.$parent.AttachmentsRelatedToEntityId)
entityName = $scope.AttachmentsRelatedToEntityId;
return entityName;
}
$scope.getAttachmentEntityId = function(choice)
{
var entityId = null;
if (choice && choice)
entityId = choice.id;
// old...
if (!entityId && $scope.$parent.AttachmentsRelatedToEntity)
entityId = $scope.$parent.AttachmentsRelatedToEntity.Id;
return entityId;
}
*/
$scope.refreshAttachments = function()
{
if (!$scope.AttachmentsRelatedToEntityId)
return;
var entityName = null;
var entityId = null;
if ($scope.$parent.AttachmentsRelatedToEntity)
{
entityName = $scope.$parent.AttachmentsRelatedToEntity.EntityId;
entityId = $scope.$parent.AttachmentsRelatedToEntity.Id;
}
if (!entityName)
entityName = $scope.AttachmentsRelatedToEntityId;
// clear lists
$scope.entityRelatedAttachments = [];
$scope.linkedEntityRelatedAttachments = [];
$scope.classRelatedAttachments = [];
if (entityId)
{
$scope.searchEntityRelatedAttachments($scope.$parent.AttachmentsRelatedToEntity);
$scope.searchLinkedEntityRelatedAttachments($scope.$parent.AttachmentsRelatedToEntity, $scope.$parent.AttachmentsRelatedToEntityLayout);
}
$scope.searchClassRelatedAttachments(entityName);
}
$scope.downloadAttachment = function(attachment)
{
if (!attachment || !attachment.InternalFilename || attachment.InternalFilename == '')
return;
$window.open(T3_API_ATTACHMENT_download_url + '/' + attachment.InternalFilename, '_blank');
}
$scope.buildLinkToId = function(id) {
//var url = T3_APP_base_url + '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D';
var url = '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D';
url = url.replace(/\/$/, ""); // Remove ending /
if (id)
return url + '/' + id;
else
return url;
}
$scope.buildLinkToOtherEntityId = function(otherEntity, id) {
//var url = T3_APP_base_url + '\x7B\x5B\x7B\x20buildLinkToOtherEntityId\x28attachment_AttachmentEntityName,\x20attachment_AttachmentEntityId\x29\x20\x7D\x5D\x7D';
var url = otherEntity;
url = url.replace(/\/$/, "");
if (id)
return url + '/' + id;
else
return url;
}
$scope.showAttachment = function(attachment)
{
if (!attachment)
return;
$window.open($scope.buildLinkToOtherEntityId('Attachment', attachment.Id), '_blank');
}
$scope.deleteAttachmentWithConfirm = function(ev, attachment) {
// Appending dialog to document.body to cover sidenav in docs app
var confirm = $mdDialog.confirm()
.title(T3_NG_confirm_delete)
.textContent(T3_NG_confirm_delete_you_cannot_rollback)
.ariaLabel(T3_NG_confirm_delete)
.targetEvent(ev)
.ok(T3_NG_confirm_delete_yes)
.cancel(T3_NG_confirm_delete_no);
$mdDialog.show(confirm).then(function() {
$scope.deleteAttachment(attachment);
}, function() { });
};
$scope.deleteAttachment = function(attachment)
{
if (!attachment)
return;
$scope.AttachmentData = attachment;
$method = 'DELETE';
$url = T3_API_ATTACHMENT_url;
if ($scope.AttachmentData.Id > 0)
$url = $url + '/' + $scope.AttachmentData.Id;
$http({
method: $method,
url: $url,
headers: T3_API_authorized_request_headers($scope.loginData.token),
data: encodeJsonReferences($scope.AttachmentData)
}).then(function onSuccess(response) {
// Handle success
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
$scope.refreshAttachments();
}).catch(function onError(response) {
// Handle error
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
if (status > 0)
$scope.$parent.showFeedbackMessage(T3_NG_TEXT_ATTACHMENT_delete_error, 'error');
});
}
$scope.close = function () {
// Component lookup should always be available since we are not using `ng-if`
$mdSidenav('attachmentsidenav').close();
};
$scope.showSuccessToast = function(msg) {
$mdToast.show(
$mdToast.simple()
.textContent(msg)
.position('bottom')
.theme('success-toast')
.hideDelay(3000)
// .textContent(msg)
// .position('bottom')
// .theme('success-toast')
// //.hideDelay(3000)
// .actionKey('o')
// .actionHint('Ok, ho capito.')
// .action('Ok')
// .dismissHint('')
// .highlightAction(true)
// // Accent is used by default, this just demonstrates the usage.
// //.highlightClass('md-accent')
// //.position(pinTo)
// .hideDelay(0);
);
};
$scope.showWarningToast = function(msg) {
$mdToast.show(
$mdToast.simple()
// .textContent(msg)
// .position('bottom')
// .theme('warning-toast')
// .hideDelay(3000)
.textContent(msg)
.position('bottom')
.theme('warning-toast')
//.hideDelay(3000)
.actionKey('o')
.actionHint('Ok, ho capito.')
.action('Ok')
.dismissHint('')
.highlightAction(true)
// Accent is used by default, this just demonstrates the usage.
//.highlightClass('md-accent')
//.position(pinTo)
.hideDelay(0)
);
};
$scope.showErrorToast = function(msg) {
$mdToast.show(
$mdToast.simple()
// .textContent(msg)
// .position('bottom')
// .theme('error-toast')
// .hideDelay(3000)
.textContent(msg)
.position('bottom')
.theme('error-toast')
//.hideDelay(3000)
.actionKey('o')
.actionHint('Ok, ho capito.')
.action('Ok')
.dismissHint('')
.highlightAction(true)
// Accent is used by default, this just demonstrates the usage.
//.highlightClass('md-accent')
//.position(pinTo)
.hideDelay(0)
);
};
$scope.FeedbackMessage = '';
$scope.isFeedbackMessage = false;
$scope.clearFeedbackMessage = function() {
$scope.FeedbackMessage = '';
$scope.isFeedbackMessage = false;
}
$scope.showFeedbackMessage = function(msg, type) {
if (!type)
{
$scope.showSuccessToast(msg);
return;
}
switch(type) {
case 'error':
$scope.showErrorToast(msg);
break;
case 'warning':
$scope.showWarningToast(msg);
break;
default:
$scope.showSuccessToast(msg);
}
// $scope.showSuccessToast(msg);
// $scope.FeedbackMessage = msg;
// $scope.isFeedbackMessage = true;
// setTimeout($scope.clearFeedbackMessage, 3000);
}
$scope.clearFeedbackMessage();
})